I am fairly new to iphone development and programming in general and am wondering how to read some text from a text file to be diplayed in a UITextView. I have tried various ways to do it but just can’t seem to be able to get it to display:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"txt"];
NSString *someText=[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
textView.text=someText;
Some sample code would be greatly appreciated. Thanks in advance
I had to change the name of the text file to ‘untitled.txt’ from just plain ‘untitled’ in Xcode. It was a text file but didn’t have the extension of
.txt. This doesn’t seem to be automatically appended if you create the text file in Xcode.