そのため、UITextview にセグエする UITableView を使用して何かを書き込もうとしています。
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]];
}
}
そしてまた。ファイルシステムのファイルから読み取ったデータでテキストビューテキストを設定しようとしていますが、機能していません...
-(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];
}
例外を引き起こすために、セグエ中に何か間違ったことをしましたか? 他のコードが必要な場合は、それを立ててください。
前もって感謝します