问题
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