webView加载url,加载指定字符串


//加载url
-(void)addWebView{ UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, zScreenWidth, 480)]; NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@",URL]]]; webView.delegate=self; [self.view addSubview: webView]; self.HUB=[ZJStaticFunction showHubView:self.view]; if ([ZJStaticFunction isUserNetOK]) { [self.HUB show:YES]; [webView loadRequest:request]; }else{ [ZJStaticFunction alertView:self.view msg:remindNetWord]; } } // 让浏览器加载指定的字符串,使用m.baidu.com进行搜索 - (void)loadString:(NSString *)str { // 1. URL 定位资源,需要资源的地址 NSString *urlStr = str; if (![str hasPrefix:@"http://"]) { urlStr = [NSString stringWithFormat:@"http://m.baidu.com/s?word=%@", str]; } NSURL *url = [NSURL URLWithString:urlStr]; // 2. 把URL告诉给服务器,请求,从m.baidu.com请求数据 NSURLRequest *request = [NSURLRequest requestWithURL:url]; // 3. 发送请求给服务器 [self.webView loadRequest:request]; }
原文地址:https://www.cnblogs.com/OIMM/p/9009981.html