Thursday, July 31, 2014

iphone: reading file and loading data into textview

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"txt"];
if (filePath) {
    NSString *content = [NSString stringWithContentsOfFile:filePath];
if (content) {

    textView.text= content;
}


For loading HTML data into file
 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
    if (filePath) {
        NSString *content = [NSString stringWithContentsOfFile:filePath];
        if (content) {
             NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
           textView.attributedText = attributedString;
        }
        
    }

No comments:

Post a Comment