ios - 如何在 iPhone 的 webview 中从字符串中打开 url

标签 ios uiwebview iphone

我只想从我的字符串中打开一个 url 我的字符串已经有了我只想在 UIWebView

中显示的 url
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];

我遇到了这个错误

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

最佳答案

将此添加到您的方法中:

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

关于ios - 如何在 iPhone 的 webview 中从字符串中打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3385210/

相关文章:

javascript - 为什么 WebSQL 不能与使用 PhoneGap 制作的 iOS 应用程序一起使用?

ios - Parse.com 查询和应用程序设计问题 : A long-running operation is being executed on the main thread

objective-c - 使用自定义 NSURLProtocol 时 UIWebView 不加载重定向页面的内容

iPhone兼容性

ios - 如何在swift中引用NSObject类中的viewcontroller?

ios - 如何知道 View 何时会从后台变为事件状态

ios - libdispatch.dylib 中的 _dispatch_main_queue_callback_4CF$VARIANT$mp 和 _dispatch_main_queue_callback_4CF$VARIANT$up 有什么区别?

ios - Swift 中的 UIWebView : exc_bad_access

ios - UIWebView 中的进度条

iOS 本地化在 Xcode 中不适用于 Objective-C 中的自定义标签