In my application I have a UIWebView
in which I need to add browser like functionality(user can goBack,Forward or reload the page). To achieve this I have used the code for this tutorial.
In my code I have only one change in viewDidLoad
:
I am loading data from a local html file like this:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"File name" ofType:@"html" inDirectory:NO];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[self.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
instead of:
NSURL* url = [NSURL URLWithString:@"http://iosdeveloperzone.com"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
After loading initial html file if I am making any click on that page than the back button should get enabled, instead of its getting enabled after second url click and so that I am not able to go back to the original home page.
Please help me with this.
Thanks.
I got an answer. It's because you load data into the webView
without loadRequest
. If you load data
into webView
as a string, then it won't have any url
to go back or load the old page. So it won't store the data you given to the webView
. For that, you need to provide the url
as like this.
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"File name" ofType:@"html"] isDirectory:NO]]];