57.加载json文件 webview加载网页
2015-08-04 22:19
113 查看
1.加载json文件 和加载plist文件类似,给定文件路径即可,不同的是json文件需要加载为data,然后通过json序列化类转换 NSString *path = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil]; NSData *data = [NSData dataWithContentsOfFile:path]; NSArray *dictArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:NULL];
2.webview加载网页 // 利用自定义的webview加载网页 UIWebView *webView = (UIWebView *)self.view; webview.frame = self.view.bounds; webView.delegate = self; // 1.获得网页的全路径 NSString *path = [[NSBundle mainBundle] pathForResource:self.helpModel.html ofType:nil]; // 2.根据全路径创建url NSURL *url = [[NSURL alloc] initFileURLWithPath:path]; // 3.根据url创建request NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; // 4.加载本地的网页 [webView loadRequest:request]; // 网页加载完毕之后调用 - (void)webViewDidFinishLoad:(UIWebView *)webView { //NSLog(@"webViewDidFinishLoad"); //当网页加载完毕之后执行javascript代码,跳转到对应的位置 // 1.生成对应的javascript代码,通过一个id跳到不同的标题 NSString *jsStr = [NSString stringWithFormat:@"window.location.href = '#%@';", self.helpModel.tagId]; [webView stringByEvaluatingJavaScriptFromString:jsStr]; }
相关文章推荐
- Android自定义注册页面提示,替换Toast功能
- AndroidStudio Tips
- iOS中的字符串操作大全
- angularJS--apply() 、digest()和watch()方法
- angularJS--apply() 、digest()和watch()方法
- android Looper Handler机制
- cause:Permission Denial: receiving Intent act=android.provider.Telephony.SMS_RECEIVED
- 【Objective-C编程】import、include及@Class的孽缘
- 浅谈WebView
- 【Mac版】安装 Android Studio 及配置环境变量步骤
- Cocos2d-x android使用onKeyDown监听返回键实现二次返回退出
- iOS设计模式 - 代理
- Objective-C id和instancetype
- Android Looper And Hander 机制剖析 - 01
- 【Android-BUG篇】error opening trace file: No such file or directory
- 学习笔记11:Scala中伴生类和伴生对象中Apply方法的应用
- iOS开发概述-12.手势处理
- Android 五步修改状态栏颜色
- Android Textview属性详解
- Android ListView小常识