Reputation: 6152
I have implemented UIWebView
in my project to show some HTML data. The problem is I have loaded the webview with some HTML string by using the method
[myWebView loadHTMLString:Data baseURL:nil];
Now I want to add action of button such that when user click on the button the new data is loaded in the webview. such that
-(void)clicked{
[myWebView loadHTMLString:newData baseURL:nil];
}
I tried by applying the same as above but no affect was there. I also tried [myWebView reload], but nothing happened.
Plz tell me the appropriate method.
Upvotes: 1
Views: 12268
Reputation: 1555
Even after trying accepted answer I have not got my issue solved.
So, after spending some time I found below logic which works for me:
Objective-c
dispatch_async(dispatch_get_main_queue(), {
[myWebView reload];
})
Swift
dispatch_async(dispatch_get_main_queue(), {
myWebView.reload()
})
Upvotes: 0
Reputation: 18225
loadHTMLString:baseURL:
is the correct method.
But still some things might be wrong, such as the data you are trying to send to the webview. Did you try logging your newData object to see what is being send to the webView object?
Is your newData string loaded from a resource file? If so, you could try loading you html data from the resources with something like the code bellow
NSString *html = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myFileName" ofType:@"html"]];
[myWebView loadHTMLString:html baseURL:nil];
Upvotes: 0
Reputation: 31720
TRy with, First call stopLoading then reload on your UIWebView
instance.
[myWebView stopLoading ];
[myWebView reload];
Upvotes: 4