我有一个加载html文件的UIWebView。用户点击链接后,我希望在自定义UIWebview中打开网址。 我尝试了一些事情:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyiPadHTML"
ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
else {
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyHTML"
ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
这是我,加载文件,具体取决于设备。这很好用。我是在- (void)viewDidLoad
方法
答案 0 :(得分:2)
不应该这样吗?
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
[myOtherCustomWebView loadRequest:request];
return NO;
}
return YES;
}