我创建了UIwebView并将其命名为:webveiw 在ViewController.h中,我添加以下代码以在safari中打开外部链接:
-(BOOL) webview:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
运行时它在我做错的地方不起作用?
答案 0 :(得分:1)
尝试设置委托:
-(void)viewDidLoad
{
myWebView.delegate = self;
}
添加协议UIWebViewDelegate:
@interface yourViewController : UIViewController <UIWebViewDelegate>