嘿,这是我在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];
这将打开 Web 视图页面,但不加载我请求的 URL。这是我的 BrowserViewController.m 的 viewDidload 页面(Web 视图,我也在 .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.
}
希望有人帮忙,因为我对此感到绝望
我认为这段代码反映了很多不稳定,因为你计算了一个本地storyLink
,清理它,记录它,然后忽略它;你从原始的、未清理的源设置browserScreen
的storyLink
属性;然后,在-viewDidLoad
,你甚至不使用它,你从你的捆绑包中得到一个文件路径。
对于最后一部分:假设您有一个文件路径字符串,您不应该使用 +URLWithString:
从中创建 URL。 文件路径不是有效的 URL 字符串。 您需要使用+fileURLWithPath:
.
此外,您还可以将文件路径计算为紧邻捆绑包。 文件真的在那里吗? 它不在内容/资源或类似的东西中?