2012-04-09 22 views
0

嘿,這是我對rootviewcontroller.m代碼(RSS頁面)需要從RSS採取項目並打開它的WebView

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.ms的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. 
} 

希望有人幫助,因爲我感到絕望它

回答

0

我認爲這代碼很可能反映很多揮舞的因爲你計算一個本地的storyLink,清理它,記錄它,然後忽略它;您從原始的未清理源中設置storyLink屬性browserScreen;那麼,在-viewDidLoad中,你甚至不使用它,你會從你的包中獲得一個文件路徑。

對於最後一部分:考慮到你有一個文件路徑字符串,你不應該使用+URLWithString:從它創建一個URL。文件路徑不是有效的URL字符串。您需要使用+fileURLWithPath:

此外,您計算文件路徑爲立即在您的包中。這真的是文件的位置嗎?它不在內容/資源或類似的東西?

相關問題