从UIWebView xcode中的safari.app中打开外部链接

时间:2017-05-12 21:20:37

标签: objective-c xcode uiwebview

我创建了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;
} 

运行时它在我做错的地方不起作用?

1 个答案:

答案 0 :(得分:1)

尝试设置委托:

-(void)viewDidLoad
{
    myWebView.delegate = self;
}

添加协议UIWebViewDelegate:

@interface yourViewController : UIViewController <UIWebViewDelegate>