The Cook
The Cook

Reputation: 1443

UIWebView redraws on view did appear, how can I prevent this?

I am working on a app using UIWebView now getting a issue listed below please help me to sort it out.

Is there any way to prevent this? My html content does not change, so can I set it as fixed content or something to draw it faster ?

This is how I set html in webview:

webView.loadHTMLString(htmlData, baseURL: nil)

Upvotes: 0

Views: 827

Answers (2)

vaibhav
vaibhav

Reputation: 4096

you can execute the code which is directing webview once in a life cycle of app or customize accordingly.

// if you are navigating your application using navigation controller enables you to come back to the rootview without executing whole code of that class associated with view.
// this doesn't apply the whole life cycle of view controller
[self.navigationController pushViewController:vc animated:YES];

// if you navigating through below code this apply the whole life cycle concept of view controller.
[self presentViewController:vc animated:NO completion:nil];

you must have a look about the life cycle of view controller here is a useful apple doc

viewController Life cycle short note

  • ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-time-only work.

  • ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen.

  • ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API.

  • ViewWillDisappear/DidDisappear - Same idea as ViewWillAppear/ViewDidAppear.

  • ViewDidUnload/ViewDidDispose - In Objective C, this is where you do your clean-up and release of stuff, but this is handled automatically so not much you really need to do here.

Upvotes: 2

Nirav D
Nirav D

Reputation: 72410

Your HTMl code is not changing, so that put your webView load code inside viewDidLoad instead of viewDidAppear, because viewDidAppear always call when your view is appear, where as viewDidLoad called single time when your view is load.

Upvotes: 2

Related Questions