我的UIViewController
方法viewDidLoad
如下:
self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-64)];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.passageUrl]];
[self.webView loadRequest:request];
self.webView.UIDelegate = self;
self.webView.navigationDelegate = self;
[self.view addSubview:self.webView];
现在我想在加载完成之前执行popViewController操作,因为有时Internet连接不好,我在其pop动作中使用下面的代码,代码立即执行但是webView无法立即停止加载,在控制器弹出之前几秒钟,任何人都对如何解决这个问题有所了解?
- (void)doBack:(id)sender {
[self.webView stopLoading];
[self.navigationController popViewControllerAnimated:YES];
}
我发现在模拟器中效果很好,事实证明问题只存在于设备中。
答案 0 :(得分:0)
试试这个
- (id)popToViewControllerWithClassname:(NSString *)className Animated:(BOOL)animated {
Class class = NSClassFromString(className);
for (UIViewController *controller in self.viewControllers) {
if([controller isKindOfClass:class]) {
[self popToViewController:controller animated:animated];
return controller;
}
}
return nil;
}
通话方法
[self.navigationController popToViewControllerWithClassname:@"TestViewController" Animated:YES];