2014-01-08 60 views
0

我有一個加載html文件的web視圖,但測試時,webview只顯示代碼而不顯示頁面。有任何解決這個問題的方法嗎?Webview傳遞html代碼

#import "ViewController.h" 

@implementation ViewController 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 
#pragma mark - View lifecycle 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"html"]; 
    NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; 
    [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iphone" 
ofType:@"html"]isDirectory:NO]]]; 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 

回答

0

您可以加載HTML字符串直接

[myWebView loadHTMLString: htmlString baseURL: nil]; 
0

[myWebView loadHTMLString: htmlString baseURL:[[NSBundle mainBundle] bundleURL]];