我已經創建了一個UIViewController與UIWebView
並試圖添加爲另一個UIViewController的子視圖。這會導致崩潰,從而發送錯誤的請求錯誤。iphone sdk:UIWebView崩潰
包含的WebView代碼控制器是如下:實現WebViewController是
@interface WebViewController : UIViewController
@end
@interface WebViewController() <UIWebViewDelegate>
{
IBOutlet UIWebView *webView;
}
@end
@implementation WebViewController
- (void)viewDidLoad {
[super viewDidLoad];
webView.delegate = self;
NSString *str = [NSString stringWithFormat:@"<html><body>This is html text</body></html>"];
[webView loadHTMLString:str baseURL:nil];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}
代碼:
WebViewController *obj = [self.storyboard instantiateViewControllerWithIdentifier:@"webView"];
[self.view addSubview:obj.view];
你必須保持強大的refrence爲WebViewController * OBJ所以它不會被釋放,例如[自addChildViewController:OBJ]。或者讓一些資產在某個地方上漲 – 2014-12-03 12:57:18