如何在textview上顯示創建的文件名和內容?這是我的代碼。 Iam能夠在NSLog中顯示文件名及其內容,但不能在textview中顯示,儘管我已經給出了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;
}
要顯示文件內容,我建議使用QLPreviewController – Apple
如果插座連接爲什麼分配一個新的實例?刪除該行並重試 –