Mohammad Shaker
Mohammad Shaker

Reputation: 185

xcode - Load UIWebView from local html file

i am new to ios so excuse me if i write something wrong First as appear in .m file i read file and append some code its work fine and display data as expected except in one ,

it convert html tags to (& lt ;) but without space

this make my web view why that happen

.h file

@interface FullReport : UIViewController<UIWebViewDelegate >
@property (weak, nonatomic) IBOutlet UIWebView *web;

.m file

- (void)viewDidLoad
{
     //read FilePath
     NSString * myPath= [[NSBundle mainBundle] pathForResource:@"content" ofType:@"txt"];
    // read file content html code 
        NSString *fileContent = [[NSString alloc]initWithContentsOfFile:myPath encoding:NSUTF8StringEncoding error:nil];
    // append some code to it 
        fileContent = [fileContent stringByAppendingString:reportBody];
        NSLog(@"content file %@",fileContent);
    // laod it into my UIWebView 
        [web loadHTMLString:fileContent baseURL:[NSURL fileURLWithPath:myPath]];

    [super viewDidLoad];

}

enter image description here enter image description here

Upvotes: 0

Views: 386

Answers (1)

Ramesh Muthe
Ramesh Muthe

Reputation: 811

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:<filepath>]]];

here filepath is the path of the file content stored.

Upvotes: 1

Related Questions