iOS 7 UIWebView doesn't load webpage

会有一股神秘感。 提交于 2019-12-03 11:31:45

I moved the loadRequest method to the completion handler of a presentViewController and it works in iOS 5, 6 and 7:

[self presentViewController:gwvc animated:YES completion:^(void){
    [gwvc.wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.walkjogrun.net/about/eukanuba.html"]]];
}];
Bruce Tsai

I found the root cause. maybe I incorrectly used UIWebView, but it works in iOS5 and iOS6. I don't know why it works in earlier iOS versions...

Moreover, it works in iOS7 when I build code with SDK 6.1.

Here's my old code.

     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];
   }

I moved the loadRequest from the viewDidLoad method to the ViewWillAppear method, then it worked. I think maybe UIWebView is not initialized correctly in my old code for iOS7.

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