ios 如何从 iPhone 的 webview 中的字符串打开 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3385210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:29:55 来源:igfitidea点击:
How to open url from string in webview for iPhone
提问by ram
I want to just open a url from my string
my string is already having url I just want to show in UIWebView
我只想从我的字符串中打开一个 url 我的字符串已经有我只想显示的 url UIWebView
myString=http://maps.google.com/maps?zoom=8&sensor=false&lci=transit&layer=traffic&saddr=1.31224,103.865&daddr=1.310664,103.857132
NSString *urlString = [myString absoluteString];
NSString *urlAddress =myString;//
NSURL *url = [NSURL URLWithString:urlString ];
NSLog(@" url is %@",url); its null
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSLog(@" url req is %@",url);
//Load the request in the UIWebView.
[webe loadRequest:requestObj];
I am getting this error
我收到此错误
se&lci=transit&layer=traffic&saddr=1.31224,103.865&daddr=1.310664,103.857132
2010-08-02 13:20:08.253 Wat2Eat[5332:207] *** -[NSCFString absoluteString]: unrecognized selector sent to instance 0x1ac570
2010-08-02 13:20:08.267 Wat2Eat[5332:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString absoluteString]: unrecognized selector sent to instance 0x1ac570'
2010-08-02 13:20:08.283 Wat2Eat[5332:207] Stack: (
回答by Atma
Add this to your method:
将此添加到您的方法中:
NSString *urlAddress = @"http://myurl.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[detailWebView loadRequest:requestObj];
回答by Frank
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *websiteUrl = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest];
}