//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;
}