每次加载时停止 UIWebView 加载设置的 URL
我有一个包含多个 UIWebView 的应用程序,当我按下按钮调出一个时,它会加载设置的 URL.
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.
现在我相信这可以用 UITabBarController 来完成,但它占用了我想要实现的很多屏幕空间,所以我用 UISegmentedController 实现了这个开关.
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.
我有这个代码最初在我的 viewDidLoad 方法中加载网站:
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];
在这个SO问题上,我发现您可以通过以下方式停止加载网页:
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];
}
现在我知道我需要调整那个答案,但是我正在尝试做的事情是可能的,还是使用 SegmentedControl 总是会导致 UIWebView 重新加载并且我是否会被迫使用 TabBar?
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?
干杯杰夫
使用 NSUserDefaults 记录是否是第一次并采取相应措施.
use NSUserDefaults to record if it is the first time or not and act accordingly.