我的代码必须更新网页视图和下载网站。但它并不是因为URLWithString
返回null。我怎么解决这个问题? {0}已被弃用。
stringByAddingPercentEscapesUsingEncoding
答案 0 :(得分:0)
尝试
-(void) setWebViewMain:(NSString *) link {
// link = @"http://www.rbc.ru/society/05/09/2017/59ae2dfe9a794753f05e3e06"; if this string uncomment code is working
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@",link]];
NSLog(@"%@",url); // here url is (null)
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
// [self.webView reload];
}
答案 1 :(得分:-3)
只需删除方法中的最后一行即可:
-(void) setWebViewMain:(NSString *) link {
// link = @"http://www.rbc.ru/society/05/09/2017/59ae2dfe9a794753f05e3e06"; if this string uncomment code is working
NSURL *url = [NSURL URLWithString: link];
NSLog(@"%@",url); // here url is (null)
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
//[self.webView reload];
}
您可以这样称呼它:
[self setWebViewMain:@"http://www.rbc.ru/society/05/09/2017/59ae2dfe9a794753f05e3e06"];