【发布时间】:2015-03-06 20:49:59
【问题描述】:
我在下面的这段代码中打开了一个带有网站 URL 的 UIwebview,这是一个非常繁重的电子商务网站。一旦我开始浏览该站点,我就会遇到一个页面开始加载但没有完成的块。 就像在我的 UIWebViewDelegate 中一样,调用了 webViewDidStartLoad 但没有调用 webViewDidFinishLoad...
我的 viewcontroller.h 文件:
#import <UIKit/UIKit.h>
@interface WVTesterViewController : UIViewController <UIWebViewDelegate>
@end
我的 .m 文件:
#import "WVTesterViewController.h"
@interface WVTesterViewController ()
@end
@implementation WVTesterViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *view = self.view.subviews[0];
view.delegate = self;
NSURL *url = [NSURL URLWithString:@"<<< MY WEBSITE URL >>>"];
[view loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Failed to load with error :%@",[error debugDescription]);
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"webViewDidStartLoad :");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"webViewDidFinishLoad :");
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"shouldStartLoadWithRequest :");
return true;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
知道为什么会发生这种情况,下面是我的网络线程的屏幕帽,它挂起,我的应用程序已经死在水中了。
https://www.dropbox.com/s/ufmbncjbz0x0vbi/Screenshot%202015-03-06%2015.41.08.png?dl=0
其他信息
-
WebThread的 CPU 使用率为 100%,表明正在发生无限循环。 - 网络线程调用的方法的名称表明循环是在初始页面加载期间发生的。
- 当主线程需要在
WebThread上运行代码时会发生死锁,导致它无限期地阻塞等待无限循环结束 - 在生产代码中,
UIWebView是UIViewController的IBOutlet属性,但在我们最小的可重现示例中,我们试图尽可能避免 IB 魔法。
【问题讨论】:
标签: ios objective-c uiwebview