所以我试图用一个 UITableView 来写一些东西,这个 UITableView 是一个 UITextview 。
在 UITextview 中有一个按钮来清除文本。我有 2 个问题。
现在我得到一个错误
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<textViewController 0x6e69760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clearButton.'
断点说这是在 didSelectRowAtIndexPath 内部调用 performSegue 时抛出的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"segueIdentifier" sender:self];
}
这里
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if( [segue.identifier isEqualToString:@"fileSelected"]){
textViewController *nextViewController = segue.destinationViewController ;
nextViewController.title = @"newView";
[nextViewController setText:[[NSString alloc] initWithData:[self readFromFile:@"textfile.txt"] encoding:NSUTF8StringEncoding]];
}
}
并且。我试图用我从文件系统中的文件中读取的数据设置 textview 文本,这是读取和写入功能,但它不起作用......
-(NSData*) readFromFile:(NSString *)filename{
NSString* content = @"";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, filename];
content = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return [content dataUsingEncoding:NSUTF8StringEncoding];
}
-(void) saveToFile:(NSString *)filename withData:(NSData *)data{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@",documentsDirectory,filename];
[data writeToFile:filePath atomically:YES];
}
我在segue期间做错了什么,导致异常吗?如果您需要任何其他代码,请提出来。
提前致谢