2010-09-29 25 views
1

出於某種原因,第一種方法不顯示任何內容,而第二個作用:stringWithContentsOfFile工作,但requestWithURL不

//Common 
NSString *path=[[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"]; 
//Method1 
[webView loadRequest:[NSURLRequest requestWithURL: [NSURL fileURLWithPath: path isDirectory: NO]]]; 
//Method 2 
NSString *HTML=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL]; 
[webView loadHTMLString:HTML baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]; 
//Common   
UIViewController* controller=[webView controllerWithTitle:@"Help"]; 
[delegateRef.navController pushViewController:controller animated:YES]; 

在另一方面,我也嘗試使用URL作爲加載它好。同樣,第一種方法在第二種方法中沒有顯示任何內容。

//Common 
NSURL *url=[[NSBundle mainBundle] URLForResource:@"about" withExtension:@"html"]; 
//Method 1 
[webView loadRequest:[NSURLRequest requestWithURL:url]]; 
//Method 2 
NSString *HTML=[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]; 
[webView loadHTMLString:HTML baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]; 

奇怪的是,如果我改變URL,如下所示,那麼這兩個方法的工作(當然加載字符串不顯示CSS):

NSURL *url=[NSURL URLWithString:@"http://www.google.com"]; 

controllerWithTitle是在一個類別定義如下:

-(UIViewController*) controllerWithTitle:(NSString*)title{ 
    UIViewController *vc=[[[UIViewController alloc] init] autorelease]; 
    vc.view=self; 
    vc.title=title; 
    return vc; 
} 

回答

0

事實證明,CSS導致整個頁面不顯示!

相關問題