2016-02-11 136 views
0

我有一个现有的应用程序,当前有嵌入的帮助文件;我正在尝试更改它们,以便他们访问互联网以获得本地化的帮助文件。这是我的代码:为什么此代码不显示Google.com

// make the popover 
UIViewController* popoverContent = [UIViewController new]; 
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)]; 
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0]; // frame color? 
popoverContent.view = popoverView; 

//resize the popover view shown in the current view to the view's size 
popoverContent.preferredContentSize = CGSizeMake(450, 500); 

NSURL *indexURL = [NSURL URLWithString:@"google.com"]; 

// add the UIWebView for RichText 
webView = [[UIWebView alloc] initWithFrame:popoverView.frame]; 
webView.backgroundColor = [UIColor whiteColor]; // change background color here 

// add the webView to the popover 
[webView loadRequest:[NSURLRequest requestWithURL:indexURL]]; // load it... 
[popoverView addSubview:webView]; 

// if previous popoverController is still visible... dismiss it 
if ([popoverController isPopoverVisible]) { 
    [popoverController dismissPopoverAnimated:YES]; 
} 

//create a popover controller to display the HELP text 
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent]; 

[popoverController presentPopoverFromRect:((UIButton *)boHelpGeneralSetup).frame inView:self.view 
       permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

此代码在嵌入帮助文件时起作用;为什么当我尝试从互联网上的网页获取文件时,它不工作?

+0

当该文件嵌入? – lluisgh

+0

包含网页上* exact *语言的HTML文件。这与问题无关。 – SpokaneDude

+0

尝试使用http:// –

回答

1

从文档:

的NSURL对象被由两个部分组成,一个潜在的零基本URL 和被相对于基座URL解析的字符串。一个NSURL 对象被认为是绝对的,如果它的字符串部分完全解析为 没有基础;所有其他URL都被认为是相对的。

例如,构造一个NSURL对象时,你可以指定 文件:///路径/到/ WEB_ROOT /基础网址和文件夹/ file.html作为 字符串的一部分,具体如下:

在您的情况下,google.com被视为字符串部分,但不是基地址。由于地址以http开头,因此您需要包含url的完整路径。

所以,这将是:

NSURL *indexURL = [NSURL URLWithString:@"https://www.google.com"]; 
+0

再次感谢... – SpokaneDude

+0

不客气!确保你使用https而不是http。苹果让用户从ios9开始使用https。 –