Stop UIWebView from loading the set URL everytime when it gets loaded

Deadly 提交于 2019-12-11 23:19:02

问题


I have an app with several UIWebView's and when I press the button to bring one up it loads the set URL.

Now I would like this to happen the first time, as the webpage needs to load, but what if I want to flick between the different Views? I would like it to stay at the page it was when I left it.

Now I do believe this can be done with the UITabBarController, but it takes up to much screen real estate for what I want to achieve, so I have implemented the switch with a UISegmentedController.

I have this code to load the website initially in my viewDidLoad method:

NSString *urlAddress = @"http://google.com";  
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];

and on this SO question I found that you can have a webpage stop loading with:

UIWebView *webView = [self.view viewWithTag:10];
if(webView)
 {
  [webView stopLoading];
 }

Now I know I need to adjust that answer, but is what I am trying to do possible, or will the use of a SegmentedControl always cause the UIWebView to reload and will I be forced to use the TabBar?

Cheers Jeff


回答1:


use NSUserDefaults to record if it is the first time or not and act accordingly.



来源:https://stackoverflow.com/questions/10711027/stop-uiwebview-from-loading-the-set-url-everytime-when-it-gets-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!