UIWebView will not start after loading HTML in iOS

I had this problem in my iPhone app: I have a webView that first loads with an HTML string. After the user clicks on the link and loads the requested page, webView will not return when I call the [UIWebView goBack]; method [UIWebView goBack]; Suppose WebView does not cache an HTML string. Is there any way to make the webView cache my HTML string without having to save it in NSString itself?

+4
source share
3 answers

You can use the canGoBack property, and if you cannot return, reload the UIWebView with the original html. If the user clicked on links by links, the canGoBack property will return YES and goBack can be launched in UIWebView. _htmlString is a member variable that is set when a UIWebView is initialized using an HTML string. -rrh

 - (void)goBack { if (_htmlString && ![_browserWebView canGoBack]) { [_browserWebView loadHTMLString:_htmlString baseURL:nil]; return; } [_browserWebView goBack]; } 
+5
source

It looks like your webview variable is not properly associated with the webview instance you are using. Breakpoint on this call and check if your webView variable is "zero".

If so, make sure your webView in your XIB file is associated with the IBOutlet variable in Interface Builder. This is a common mistake and what I usually forget when developing a new page for the first time.

This tutorial discusses LOT on how to create interfaces using Interface Builder, which I am sure you are familiar with, but for those that are not also useful. This one has some good screenshots that help illustrate what I mean by “snapping” better than I type in “click the + sign and drag the little thing onto the user interface element” :)

http://www.icodeblog.com/2008/07/30/iphone-programming-tutorial-connecting-code-to-an-interface-builder-view/

EDIT

The only thing I can think of is that you are rewriting the webView variable by reinitializing it somewhere (it is already XIB-initialized) and therefore you are calling goBack on a webview that does not exist on the screen.

0
source

Try creating an NSURLRequest from the file URL and use loadRequest instead of loadhtmlString

 NSURL *htmlFileUrl = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"]; NSURLRequest *localRequest = [NSURLRequest requestWithURL:htmlFileUrl]; self.webView.delegate = self; [self.webView loadRequest:localRequest]; 
0
source

Source: https://habr.com/ru/post/1391572/


All Articles