Question

In my app I have a sliding view that holds UIWebView, that I want to substitute with another UIWebView that has already loaded content on user tap instead of loading the current view.

I tried just simply assign one view to another:

UIWebView* webView1 = [[UIWebView alloc] initWithFrame:frame];
UIWebView* webView2 = [[UIWebView alloc] initWithFrame:frame];

webView1 = webView2; // didn't work

Any help is highly appreciated!

Was it helpful?

Solution

If you need to keep them both around, you could just hide the one that should go away:

[webView1.superview addSubview: webView2];
[webView1 setHidden: YES];

OTHER TIPS

Try this:

[webView1.superview addSubview: webView2];
[webView1 removeFromSuperview];

My solution:

  1. Get the whole HTML string of the webView2:

    NSString *htmlString = [webView2 stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];

  2. Load this HTML string to webView1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top