简体   繁体   English

如何在iPhone的Webview中从字符串打开URL

[英]How to open url from string in webview for iPhone

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: (

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];
- (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]; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM