WebKitErrorDomain错误101

以下代码会产生以下错误:

WebKitErrorDomain error 101 

码:

 -(Void) searchBarSearchButtonClicked: (UISearchBar *) activeSearchBar { NSString * query = [searchBar.text stringByReplacingOccurrencesOfString: @ "" withString: @ "+"]; NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "http://http://www.google.com/search?q =%, query]]; NSURLRequest * requestObj = [NSURLRequest requestWithURL: url]; [Home loadRequest: requestObj]; } -(Void) loadView { [Super loadView]; CGRect bounds = [[UIScreen mainScreen] applicationFrame]; searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake (0.0, 0.0, bounds.size.width, 48.0)]; searchBar.delegate = self; [Self.view addSubview: searchBar]; } 

我不会说英语,只能靠翻译。 由于语言问题,这可能是键盘问题,还是编码问题?

根据WebKitError头,错误101的意思是,“WebKitErrorCannotShowURL”这是不是很有帮助。

这一行是不正确的:

 NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "http://http://www.google.com/search?q =%, query]]; 

…应该是这样的:

 NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "http://www.google.com/search?q =%@", query]]; 

我不确定是否由于生成错误的URL而导致错误,或者是否是错字。

不要在stringurl中包含空格。

确保你的url不包含空格和换行符。

要做到这一点,你可以使用下面的代码:

 NSString *newString = [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];