我的应用程序使用UIWebview,它在iOS 5和iOS 6中运行良好。但是,当我在Xcode 5中构建并运行相同的代码时,它不会在iOS 7中加载网页。
- (void)webViewDidFinishLoad:(UIWebView *)webView {}
- (void)webViewDidStartLoad:(UIWebView *)webView {}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {}
不调用所有委托函数。但我确实在xib文件和代码中设置了委托
self.theWebView.delegate = self;
我没有通过谷歌找到任何信息。感谢您的帮助。
我将loadRequest方法移动到presentViewController的完成处理程序,它在iOS 5,6和7中工作:
[self presentViewController:gwvc animated:YES completion:^(void){
[gwvc.wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.walkjogrun.net/about/eukanuba.html"]]];
}];
我找到了根本原因。
也许我错误地使用了 UIWebView
,但它适用于iOS5和iOS6。
我不知道为什么它在早期的iOS版本中有效...
此外,当我使用SDK 6.1构建代码时,它可以在iOS7中运行。
这是我的旧代码。
RechargeWebPageViewController *webPageViewController;
webPageViewController = [[ RechargeWebPageViewController alloc] initWithNibName:@"WebPage" bundle:nil];
if (webPageViewController != nil) {
webPageViewController.hidesBottomBarWhenPushed = YES;
webPageViewController.delegate=self;
[self.navigationController pushViewController:webPageViewController animated:YES];
NSURL *url = [NSURL URLWithString:@"https://xxx.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[webPageViewController loadRequest:request];
[request release];
}
我感动了 loadRequest
来自 viewDidLoad
方法 ViewWillAppear
方法,然后它工作。
我想也许吧 UIWebView
在iOS7的旧代码中未正确初始化。