I want to read a text file called “config.txt” from my application’s bundle and display it in a UITextView. The code below is not working, can anyone help me?
IF i want to display it on a View then what i should do as well.
I have a IBOutlet to a UITextView, also please tell me how to change the text font and colour programmatically.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"txt"];
if (filePath) {
NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding];
if (myText) {
textView.text= myText;
}
}
[super viewDidLoad];
Check to make sure
textViewis notniland that you setup the IBOutlet connection in Interface Builder.To set the font and color of the UITextView programmatically, use:
and
See: