-2

I have a UIWebView which load a page when the user navigates he can go to 7 levels I mean he can go to 7 different pages with different URL.

Now I want to go back to the first page directly instead of going back one by one.

I couldn't find any API in UIWebView to do this so I thought to loading the first page url again but UIWebView's cangoback will return true.

So I thought I will reinitialise the webview and load the URL

self.webview=[self.webview init];

as expect it loads the new url and UIWebView's cangoback returns false which is good.

but the problem is when I try to scroll the page down I can see the previous page behind it as background of scrollview.

Any ideas on how to fix the issue

Gaurav Patel
  • 532
  • 1
  • 5
  • 19
Elstine P
  • 340
  • 4
  • 22

1 Answers1

1

You're leaving the old web view alive, but just calling it's init routine (which you shouldn't do more than once). Instead, call:

self.webview = [[UIWebView alloc] init];

That will give you a whole new web page like you originally started with, and will invoke ARC to dispose of the old one.

Owen Hartnett
  • 5,925
  • 2
  • 19
  • 35
  • It removes all the constraints that's assigned to the webview and webview couldn't be seen in the screen at all – Elstine P Jun 06 '18 at 08:33
  • 1
    There's a couple of options: 1) you could save the constraints before you replace the webview and add them back in. 2) Use JavaScript to clear the page and history as in this post: https://stackoverflow.com/questions/3799918/how-to-clear-back-forward-list-in-uiwebview-on-iphone with the following command: [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"]; – Owen Hartnett Jun 06 '18 at 14:17
  • saving the constraints... do you mean assign the constraints to a local constraint property. – Elstine P Jun 07 '18 at 15:15
  • I will check and let you know – Elstine P Jun 07 '18 at 15:34