对UIWebView的学习
建工程,建一个类WebViewController 继承于UIViewController
#import "WebViewController.h" @interface WebViewController ()
{
UIWebView *_webView;
UITextField *_textField;
UIActivityIndicatorView *_activityIndicatorView;
}
@end @implementation WebViewController
-(void)dealloc
{
[_webView release];
[_textField release];
[_activityIndicatorView release];
[super dealloc];
}
//webView获取url地址
- (void)loadWebPageWithString:(NSString *)urlstring
{
NSURL *url = [NSURL URLWithString:urlstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
//点击按钮,网页加载
- (void)buttonPress:(id)sender
{
[_textField resignFirstResponder];
[self loadWebPageWithString:_textField.text];
}
//代理中的方法
-(void)webViewDidStartLoad:(UIWebView *)webView
{
//网页加载时 进度轮开始启动
[_activityIndicatorView startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//网页加载完成 进度轮停止
[_activityIndicatorView stopAnimating];
}
//请求页面出现错误:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网址输入错误或网络断开" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
[alertView release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
_textField = [[UITextField alloc] initWithFrame:CGRectMake(, , , )];
_textField.borderStyle = UITextBorderStyleRoundedRect;
//输入框默认显示http://www.baidu.com
_textField.text = @"http://www.baidu.com";
//点击button进入网页
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(, , , );
[button setTitle:@"GO" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
//网页显示
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(, , , )];
_webView.delegate = self;
[self.view addSubview:_webView];
[self.view addSubview:_textField];
[self.view addSubview:button];
//设置进度轮
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(, , , )];
//进度轮中心位置
[_activityIndicatorView setCenter:self.view.center];
//进度轮显示类型
[_activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[self.view addSubview:_activityIndicatorView];
//没有点击按钮时,执行方法进入默认显示网页
[self buttonPress:nil]; // Do any additional setup after loading the view.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
实例代码:LiSWebView.zip
对UIWebView的学习的更多相关文章
- ios网络学习------4 UIWebView的加载本地数据的三种方式
ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...
- 关于学习是UIWebView的一些思考
前几天因为数据中加载有html语言的数据,关于html语言和UIWebView,有一些纠结,经过几天的研究,也有了一些自己的简单的见解. 我有两个页面需要加载html语言(注意,这里 ...
- (转)UIWebView全部API学习
网上找的收藏一下 http://www.myexception.cn/web/1888974.html 最生僻的API做了下划线以及粗体的标注.百度上查了全是拷贝的同一份代码,而且只有代码没有解释,很 ...
- 一步一步学习Swift之(四)玩转UIWebView
实现原理: 1.通过UIWebView的stringByEvaluatingJavaScriptFromString方法来触发脚本 2.通过自定义连接来触发oc代码 实现过程 @IBOutlet we ...
- ios学习网络------4 UIWebView以三种方式中的本地数据
UIWebView这是IOS内置的浏览器.能够浏览网页,打开文档 html/htm pdf docx txt等待格文档类型. safari浏览器是通过UIWebView制作. server将 ...
- IOS开发-UI学习-UIWebView,简单浏览器的制作
制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: ...
- ios学习之UIWebView网页视图调整
//先来一个可行的小Demo程序:结合searchBar的google搜索 #import <UIKit/UIKit.h> @interface ViewController : UIVi ...
- ios学习之UIWebView网页视图
转载于爱德凡的百度空间,地址:http://hi.baidu.com/aidfan/item/34a720866b33cbcdef083d37 UIWebView 使用详解 一.UIWebView加载 ...
- Swift学习之熟悉控件
最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...
随机推荐
- mysql linux备份shell
#!/bin/bash# export and backup the activity.sql mysqldump -uname -password activity --skip-lock-ta ...
- TaskTracker启动过程源码级分析
TaskTracker也是作为一个单独的JVM来运行的,其main函数就是TaskTracker的入口函数,当运行start-all.sh时,脚本就是通过SSH运行该函数来启动TaskTracker的 ...
- UVa 10561 - Treblecross
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- eclipse web项目实际工程路径对应
src/1.properties ---->实际路径 /WEB-INF/classes/1.propertiessrc/com.ayong.one/2.properties /WEB-INF/c ...
- ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出错解决方案
博客地址 http://blog.csdn.net/foxdave 近期了解MVC4的时候弄了一个简单的小工程,使用Entity Framework作为Model,F5启动调试运行的时候没有问题,但是 ...
- webview调用外部浏览器而不是在控件中显示
view.loadUrl(url); // 如果页面中链接,如果希望点击链接继续在当前browser中响应, // 而不是新开Android的系统browser ...
- poj3126 筛素数+bfs
//Accepted 212 KB 16 ms //筛素数+bfs #include <cstdio> #include <cstring> #include <iost ...
- uart与usart
字面意义:UART:universal asynchronous receiver and transmitter通用异步收发器:USART:universal synchronous asynchr ...
- 如何为Eclipse设置代理
看图,不解释:
- python中的namespace
python中的名称空间是名称(标识符)到对象的映射. 具体来说,python为模块.函数.类.对象保存一个字典(__dict__),里面就是重名称到对象的映射. 可以参看下面python程序的输出: ...