gpt4 book ai didi

ios - iPhone SDK : UIWebView crash

转载 作者:行者123 更新时间:2023-11-29 02:27:57 25 4
gpt4 key购买 nike

我用 UIWebView 创建了一个 UIViewController,并试图将其作为 subview 添加到另一个 UIViewController。这会导致崩溃,从而发送错误的请求错误。

包含WebView的Controller代码如下:

@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 的代码是:

 WebViewController *obj = [self.storyboard instantiateViewControllerWithIdentifier:@"webView"];
[self.view addSubview:obj.view];

最佳答案

需要添加,controller之间的关系,添加这个:

     [self addChildViewController:obj];

您的代码是:

  WebViewController *obj = [self.storyboard instantiateViewControllerWithIdentifier:@"webView"];
[self addChildViewController:obj];
[self.view addSubview:obj.view];

关于ios - iPhone SDK : UIWebView crash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27271759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com