当我运行app时,xcode调试终止

时间:2011-08-04 19:14:24

标签: xcode uitextview text-files

当我使用模拟器在Xcode中运行我的应用程序时,它只运行文件,直到我添加涉及文本文件的前三行。它给我一条消息说terminate called after throwing an instance of 'NSException'.我不知道这意味着什么,或者为什么只有当我尝试读入文本文件并将其显示在textView中时才会发生。

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"textfiles/brain_01" ofType:@"txt"];//establish file path for text file
    NSString *textFile = [[NSString alloc] stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error: nil];
    textView.text = textFile;
    [super viewDidLoad];    
    fullButton.hidden = YES;
    viewLabel.hidden = YES;
}

1 个答案:

答案 0 :(得分:1)

NSException表示您的代码中存在错误。例外是错误。在你的情况下,这可能是因为

NSString *textFile = [[NSString alloc] stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error: nil];

应该是

NSString *textFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error: nil];

stringWithContentsOfFile是用于制作NSString的类方法 - 仅使用alloc方法{/ 1}}。

相关问题