为什么此代码不显示 Google.com
Why does this code NOT display Google.com
我有一个现有的应用程序,目前已嵌入帮助文件;我正在尝试更改它们,以便它们可以访问 Internet 以获取本地化的帮助文件。这是我的代码:
// 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];
此代码在嵌入帮助文件时有效;为什么当我尝试从 Internet 上的网页获取文件时它不起作用?
来自文档:
An NSURL object is composed of two parts—a potentially nil base URL
and a string that is resolved relative to the base URL. An NSURL
object is considered absolute if its string part is fully resolved
without a base; all other URLs are considered relative.
For example, when constructing an NSURL object, you might specify
file:///path/to/web_root/ as the base URL and folder/file.html as the
string part, as follows:
在您的情况下,google.com 被视为字符串部分而不是基地址。由于地址以 http 开头,您需要包含 url.
的完整路径
所以,它将是:
NSURL *indexURL = [NSURL URLWithString:@"https://www.google.com"];
我有一个现有的应用程序,目前已嵌入帮助文件;我正在尝试更改它们,以便它们可以访问 Internet 以获取本地化的帮助文件。这是我的代码:
// 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];
此代码在嵌入帮助文件时有效;为什么当我尝试从 Internet 上的网页获取文件时它不起作用?
来自文档:
An NSURL object is composed of two parts—a potentially nil base URL and a string that is resolved relative to the base URL. An NSURL object is considered absolute if its string part is fully resolved without a base; all other URLs are considered relative.
For example, when constructing an NSURL object, you might specify file:///path/to/web_root/ as the base URL and folder/file.html as the string part, as follows:
在您的情况下,google.com 被视为字符串部分而不是基地址。由于地址以 http 开头,您需要包含 url.
的完整路径所以,它将是:
NSURL *indexURL = [NSURL URLWithString:@"https://www.google.com"];