【发布时间】:2013-01-15 16:42:11
【问题描述】:
以下代码可以正常工作,但是当我返回我的应用程序时,它会继续执行以下代码,但我不知道为什么以及如何停止它。 我认为它只发生在 ios5.0 中: 应用流程 - rootviewcontroller -> mainviewcontroller ->webview
以下代码在mainviewcontroller中webview的shouldstartloadrequest方法中调用
@property (readwrite, retain) UIWebView *_loginWebView;
...
..
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_loginWebView loadRequest:requestObj];
}
//当webview收到打开url的请求时调用following
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//return no is a special case there is more code in the method which I am not showing here
if ([[UIApplication sharedApplication] canOpenURL:myURL])
{
[[UIApplication sharedApplication] openURL:myURL];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:newPath]];
}
return NO;
}
//above is a special case
}
head 标签内容 -
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<!-- iOS Stuff -->
<link rel="apple-touch-icon" href="images/...."/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="shortcut icon" href="favicon.ico" />
<script async="async" src="https://......."></script>
<script type="text/javascript">
..........
</script>
</head>
【问题讨论】:
-
这段代码在哪里被调用?什么方法?
-
应该启动loadrequest方法
-
好吧,通过阅读两个可用的答案,我无法理解您的问题。您不希望每次您的应用程序进入前台时都刷新 web 视图,对吗?我要说的是,您可以获得一些可以在 webview:shouldStartLoadRequest: 上检查的控制标志,并决定是否要加载它。事实是我们不知道为什么要调用它,也许这就是它的行为。如果是这样,你只需要绕过它。如果这看起来完全不对,那么也许我什么都不懂。
-
可能是我用错了方式 - 试试这个 - *.com/questions/14491584/…