嘿,这是我在rootviewcontroller.m上的代码(rss页面)
NSDictionary* storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"link: %@", storyLink);
browserScreen=[[BrowserViewController alloc] initWithNibName:@"BrowserViewController" bundle:nil];
browserScreen.storyLink =[[stories objectAtIndex: storyIndex] objectForKey: @"link"];
[self.view addSubview:browserScreen.view];
这将打开WebView页面,但不会加载我请求的URL。这是我的BrowserViewController.m的viewDidload页面(网页视图,我还修补了.xib文件中的内容)
- (void)viewDidLoad
{
[super viewDidLoad];
// NSString *urlAddress = storyLink;
NSString *urlAddress = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"storyLink"];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
// Do any additional setup after loading the view from its nib.
}
希望有人帮助,因为我对此感到绝望
答案 0 :(得分:0)
我认为这段代码反映了很多因为你计算一个本地storyLink
,清理它,记录它然后忽略它;您从原始未清理的来源设置storyLink
browserScreen
属性;然后,在-viewDidLoad
,你甚至不使用它,你从你的包中得到一个文件路径。
对于最后一部分:假设您有文件路径字符串,则不应使用+URLWithString:
从中创建URL。文件路径不是有效的URL字符串。您需要使用+fileURLWithPath:
。
此外,您将文件路径计算为紧跟在包中。这真的是文件的位置吗?它不在内容/资源或类似的东西?