如何在 textview 上显示创建的文件名和内容?这是我的代码。我能够在 NSLog 中显示文件名及其内容,但不能在 textview 上显示,尽管我已经给出了 textview 的出口。请帮我解决这个问题。
-(IBAction) open: (id) sender
{
// Create instance of UITextView
textView = [UITextView alloc];
initWithFrame:[[UIScreen mainScreen] applicationFrame]];
NSString *homeDir = NSHomeDirectory();
// Add text
textView.text= homeDir;
NSLog(@"%@", homeDir);
textfield.text= @"output will go here..";
NSString *myFilePath = [[NSBundle mainBundle]
pathForResource:@"Myfile"
ofType:@"txt"];
NSString *myFileContents = [NSString stringWithContentsOfFile:myFilePath
encoding:NSUTF8StringEncoding
error:nil];
NSString *s = [NSString stringWithFormat:@"myFilePath: %@, Contents of file:%@",myFilePath, myFileContents];
NSLog(@"%@", s);
textView.text= s;
}