'UIApplication'没有可见的@interface声明选择器'openUrl:'
问题描述:
我在这里丢失了什么?我不断收到'UIApplication'没有可见的@interface声明选择器'openUrl:'
为“UIApplication的”不可见@interface声明选择“的OpenURL:”
#import "ViewController.h"
@interface ViewController()
@property (strong, readwrite, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
www.delegate = self;
[www loadRequest:[NSURLRequest
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
}
- (BOOL) webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(@"%@", [[request URL] absoluteString]);
[[UIApplication sharedApplication] openUrl:[[request URL] absoluteString]];
}
return YES;
}
@end
答
据推测,该错误信息实际上是指定不就是有没有一种方法,在全称为openURL:
,但在UIApplication
上没有方法,称为openURL:
,您需要输入NSString
参数,因为您试图在此传入。
以下应该工作:
[[UIApplication sharedApplication] openURL:[request URL]];
正如你可以看到from the documentation,openURL:
需要一个NSURL
参数,而不是一个NSString
。
答
为什么你会得到这个错误,并且你打错电话了?
是的,你的代码是不正确的。
[[UIApplication sharedApplication] openUrl:[[request URL] absoluteString]];
上面的代码显示不正确的语法,因为您称为absoluteString.So它绝对显示错误。
有没有这样的说法“的NSString”,这所采取的OpenURL
所以,你想要做什么,是你可以调用字符串的URL与URLWithString如果您absoluteString有网址和uyou可以直接调用该网址
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"https://www.google.co.in/#q=STACKOVERFLOW+IOS+QUESTIONS"]];
耐心,蚱蜢。 – matt