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

本文介绍了如何在iOS应用中使用UIWebView加载指定URL的方法,并提供了通过UIWebView加载字符串的具体实现,包括如何构造带有搜索参数的URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 


//加载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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值