2011-08-31 25 views

回答

1

你不能在URL中有空格,这就是为什么它不工作!

编辑: 为了避免您的网址中有空格,您可以检查网址是否有空格,如果显示警报。

if([url.text rangeOfString:@" "].location != NSNotFound) { 
    //url contains a space, show an alert and don't load the request here! 
} 
else { 
    //load the request into your webview! 
} 
+0

@Maxner ...感谢您的帮助。 – mukesh

+0

@mukesh hey ive在帖子中添加了一些代码。它应该是有帮助的。请接受答案! – JonasG

0

浏览器不允许空格。 Web浏览器(桌面)就像chrome一样,也就是自动将空白空格转换为百分号%。要在目标c上执行此操作,您需要使用stringByAddingPercentEscapesUsingEncoding方法进行封装。以下是一个工作示例。

NSString *myUrl = @"http://en.m.wikipedia.org/wiki/united kingdom"; 
[myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];