如何在webview for iPhone中打开来自字符串的URL [英] How to open url from string in webview for iPhone

查看:168
本文介绍了如何在webview for iPhone中打开来自字符串的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to just open a url from my string my string is already having url I just want to show in 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];

我收到此错误

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

这篇关于如何在webview for iPhone中打开来自字符串的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆