Loads the local HTML file into the web view in the app
2013-02-28 00:22
405 查看
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSString *htmlFile = [[NSBundle
mainBundle] pathForResource:@"BullsEye"
ofType:@"html"];
NSData *htmlData = [NSData
dataWithContentsOfFile:htmlFile];
NSURL *baseURL = [NSURL
fileURLWithPath:[[NSBundle
mainBundle] bundlePath]];
[self.webView
loadData:htmlData MIMEType:@"text/html"
textEncodingName:@"UTF-8"
baseURL:baseURL];
}
1. We find the BullsEye.html file in our application bundle,then we load it into an NSData object, and finally we ask the web view to show the contents of this data object.
{
[super
viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSString *htmlFile = [[NSBundle
mainBundle] pathForResource:@"BullsEye"
ofType:@"html"];
NSData *htmlData = [NSData
dataWithContentsOfFile:htmlFile];
NSURL *baseURL = [NSURL
fileURLWithPath:[[NSBundle
mainBundle] bundlePath]];
[self.webView
loadData:htmlData MIMEType:@"text/html"
textEncodingName:@"UTF-8"
baseURL:baseURL];
}
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"BullsEye" ofType:@"html"]; NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [self.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL]; }
1. We find the BullsEye.html file in our application bundle,then we load it into an NSData object, and finally we ask the web view to show the contents of this data object.
相关文章推荐
- The solution of html <input type = "file "> in webview not work
- 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded resource, ms-appdata:///, ms-local-stream://
- 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded resource, ms-appdata:///, ms-local-stream://
- Android display local image/CSS files in HTML with WebView
- Weblogic发布小问题——The root element weblogic-web-app is missing in the descriptor file
- How can I recover a file that I deleted in my local repo from the remote repo in Git?
- (对Web.config文件加密)encrypting sensitive information stored in the web.config file
- Stop the Hollyweb! No DRM in HTML5
- IOS编译报错-The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- WebView加载网页时出现“Sorry,you browser seems not to support the HTML 5 canvas element ”
- Configuring the Change Password Feature in Outlook Web App Exchange 2010
- .NET错误The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
- Eclipse导入Gradle时报错:SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable
- WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction
- iOS 报错:没有查看权限the file "xxx.app" couldn't be opened because you don't have permission to view it.
- Rails Web App Learning in action (3) ---the basic version of students selective courses Contents
- 导入第三方库报错:The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- XML错误信息Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.0.xsd). For more information, right click on the message in the Problems View ...
- 【OSC手机App技术解析】- 在WebView中组装HTML