我试图阻止主线程,直到 UIWebView 完成加载,但在调用[NSThread sleepForTimeInterval:]
后调用[UIWebView loadRequest:]
会使加载永远不会完成:webViewDidFinishLoad
在睡眠完成后调用委托。
为什么会这样?以及如何阻止主线程?
我loadPage
从打电话[ViewController willRotateToInterfaceOrientation:]
,我想做的是防止 iOS 界面旋转,直到加载了另一个方向的 webview。
- (void)loadPage {
UIWebView* webview2 = [[UIWebView alloc] initWithFrame:rect];
webview2.delegate = self;
NSString* htmlPath = ..... ; // Path to local html file
NSURL *newURL = [[[NSURL alloc] initFileURLWithPath: htmlPath] autorelease];
NSURLRequest *newURLRequest = [[[NSURLRequest alloc] initWithURL: newURL] autorelease];
[webview2 loadRequest:newURLRequest];
[NSThread sleepForTimeInterval:10.0f]; // Why this blocks the uiwebview thread ??
[self.view addSubview:webview2];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"Finished loading!");
}