2010-08-02 14 views
18

voglio aprire solo un URL da mia stringa mia stringa sta già avendo url Voglio solo mostrare in UIWebViewCome aprire url da stringa in WebView per iPhone

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

sto ottenendo questo errore

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

risposta

49

Aggiungi questo al tuo metodo:

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

Mentre questo snippet di codice può rispondere alla domanda, non fornisce alcun contesto per spiegare come o perché. Potresti aggiungere una frase o due per spiegare la tua risposta. – brandonscript

Problemi correlati