ios_webView
iOS开发中WebView的使用
在AppDelegate.m文件里
sourceprint
" class="item about" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px">?
01.#import "AppDelegate.h"02.#import "webTableViewController.h"03.@implementation AppDelegate04. 05.-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions06.{07.self.window
= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];08.//
Override point for customization after application launch.09.self.window.backgroundColor
= [UIColor whiteColor];10.webTableViewController
*web = [[webTableViewController alloc]init];11.self.window.rootViewController
= web;12.[self.window
makeKeyAndVisible];13.return YES;14.}新键一个类命名为webTableViewController
webTableViewController.h
sourceprint
" class="item about" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px">?
01.#import <UIKit/UIKit.h>02. 03.@interface webTableViewController
: UIViewController<UIWebViewDelegate>04.{05.IBOutlet
UIWebView *webView;06. 07.UIActivityIndicatorView
*activityIndicatorView;08.UIView
*opaqueView;09.}10. 11.@endwebTableViewController.m
sourceprint
" class="item about" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px">?
01.#import "webTableViewController.h"02. 03.@interface webTableViewController
()04. 05.@end06. 07.@implementation webTableViewController08.-
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil09.{10.self
= [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];11.if (self)
{12.//
Custom initialization13.}14.return self;15.}16. 17.-
(void)viewDidLoad18.{19.[super viewDidLoad];20.webView
= [[UIWebView alloc]initWithFrame:CGRectMake(0, 44, 320, 440)];21.[webView
setUserInteractionEnabled:YES];//是否支持交互22.//[webView
setDelegate:self];23.webView.delegate=self;24.[webView
setOpaque:NO];//opaque是不透明的意思25.[webView
setScalesPageToFit:YES];//自己主动缩放以适应屏幕26.[self.view
addSubview:webView];27. 28.//载入网页的方式29.//1.创建并载入远程网页31.[webView
loadRequest:[NSURLRequest requestWithURL:url]];32.//2.载入本地文件资源33./*
NSURL *url = [NSURL fileURLWithPath:filePath];34.NSURLRequest
*request = [NSURLRequest requestWithURL:url];35.[webView
loadRequest:request];*/36.//3.读入一个HTML。直接写入一个HTML代码37.//NSString
*htmlPath = [[[NSBundle mainBundle]bundlePath]stringByAppendingString:@"webapp/test.html"];38.//NSString
*htmlString = [NSString stringWithContentsOfURL:htmlPath encoding:NSUTF8StringEncoding error:NULL];39.//[webView
loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:htmlPath]];40. 41.opaqueView
= [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];42.activityIndicatorView
= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];43.[activityIndicatorView
setCenter:opaqueView.center];44.[activityIndicatorView
setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];45.[opaqueView
setBackgroundColor:[UIColor blackColor]];46.[opaqueView
setAlpha:0.6];47.[self.view
addSubview:opaqueView];48.[opaqueView
addSubview:activityIndicatorView];49. 50. 51.}52. 53.-(void)webViewDidStartLoad:(UIWebView
*)webView{54.[activityIndicatorView
startAnimating];55.opaqueView.hidden
= NO;56.}57. 58.-(void)webViewDidFinishLoad:(UIWebView
*)webView{59.[activityIndicatorView
startAnimating];60.opaqueView.hidden
= YES;61.}62. 63.//UIWebView怎样推断
HTTP 404 等错误64.-(void)connection:(NSURLConnection
*)connection didReceiveResponse:(NSURLResponse *)response{66.NSHTTPURLResponse
*httpResponse = (NSHTTPURLResponse *)response;67.if ((([httpResponse
statusCode]/100)
== 2))
{68.//
self.earthquakeData = [NSMutableData data];69.[UIApplication
sharedApplication].networkActivityIndicatorVisible = YES;70. 71.[
webView loadRequest:[ NSURLRequest requestWithURL: url]];72.webView.delegate
= self;73.} else {74.NSDictionary
*userInfo = [NSDictionary dictionaryWithObject:75.NSLocalizedString(@"HTTP
Error",76.@"Error
message displayed when receving a connection error.")77.forKey:NSLocalizedDescriptionKey];78.NSError
*error = [NSError errorWithDomain:@"HTTP" code:[httpResponse
statusCode] userInfo:userInfo];79. 80.if ([error
code] == 404)
{81.NSLog(@"xx");82.webView.hidden
= YES;83.}84. 85.}86.}87.-
(void)didReceiveMemoryWarning88.{89.[super didReceiveMemoryWarning];90.//
Dispose of any resources that can be recreated.91.}92. 93.@endios_webView的更多相关文章
随机推荐
- deep-in-es6(四)
不定参数和默认参数: function containsAll(str) { for(var i = 1;i < arguments.length;i++) { var hasStr = arg ...
- linux awk函数
这节详细介绍awk内置函数,主要分以下3种类似:算数函数.字符串函数.其它一般函数.时间函数 一.算术函数: 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y ...
- python核心编程五——映像和集合
1.字典 不同意一个键相应多个值:当有键发生冲突(即.字典键反复赋值),取最后(近期)的赋值. >>> dict1 = {' foo':789, 'foo': 'xyz'} ...
- 没有killall命令的解决方法
没有killall命令的解决方法 -bash: killall: command not found https://www.byte128.com/archives/231.html 执行killa ...
- modal模态框插件
用法: <!--模态框--> <div class="modal fade" id="myModal"> <div class=& ...
- 升级你的Linux日志系统
650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...
- Direct2D 如何关闭抗锯齿
// Each pixel is rendered if its pixel center is contained by the geometry. // D2D1_ANTIALIAS_MODE_A ...
- 简单记录几个有用的sql查询
转载自:http://blog.itpub.net/16436858/viewspace-676265/ 下面示例中,查询的数据表参考这一篇的Person表. 一.限制返回的行数 1.Sql Serv ...
- ORA-16014 ORA-00312
打开alert日志发现如下错误信息 Errors in file /oracle/app/oracle/admin/hncdfhq/bdump/hncdfhq_arc0_45285882.trc: O ...
- 2. Vue基础语法
模板语法: Mustache语法: {{}} Html赋值: v-html="" 绑定属性: v-bind:id="" 使用表达式: {{ok?'Yes': ...