【发布时间】:2010-02-24 17:09:59
【问题描述】:
我的代码编译良好,但没有显示 mathspractice.txt 中的文本
-(void)loadText
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *textFilePath = [bundle pathForResource:@"mathspractice" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath];
NSArray *mathsPracticeTextArray = [[NSArray alloc] initWithArray:[fileContents componentsSeparatedByString:@" "]];
self.mathsPracticeText = mathsPracticeTextArray;
[mathsPracticeTextArray release];
}
和:
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
myLabel.text = [mathsPracticeText componentsJoinedByString:@" "];
[myScrollView addSubview:myLabel];
[myLabel release];
谁能告诉我为什么?
【问题讨论】:
-
您是否检查过以确保将文本正确加载到 mathsPracticText 中?
-
什么是 mathsPractiveText?此外,如果您稍后再次加入,我也看不到拆分文件的目的
标签: objective-c cocoa-touch nsarray