建工程,建一个类WebViewController 继承于UIViewController

WebViewController设置为根视图控制器
WebViewController遵守UIWebViewDelegate协议以便网页视图加载或停止加载,加载出错时或执行什么方法,发生什么事件
WebViewController.m中代码 
#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的学习的更多相关文章

  1. ios网络学习------4 UIWebView的加载本地数据的三种方式

    ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...

  2. 关于学习是UIWebView的一些思考

    前几天因为数据中加载有html语言的数据,关于html语言和UIWebView,有一些纠结,经过几天的研究,也有了一些自己的简单的见解.          我有两个页面需要加载html语言(注意,这里 ...

  3. (转)UIWebView全部API学习

    网上找的收藏一下 http://www.myexception.cn/web/1888974.html 最生僻的API做了下划线以及粗体的标注.百度上查了全是拷贝的同一份代码,而且只有代码没有解释,很 ...

  4. 一步一步学习Swift之(四)玩转UIWebView

    实现原理: 1.通过UIWebView的stringByEvaluatingJavaScriptFromString方法来触发脚本 2.通过自定义连接来触发oc代码 实现过程 @IBOutlet we ...

  5. ios学习网络------4 UIWebView以三种方式中的本地数据

    UIWebView这是IOS内置的浏览器.能够浏览网页,打开文档  html/htm  pdf   docx  txt等待格文档类型. safari浏览器是通过UIWebView制作. server将 ...

  6. IOS开发-UI学习-UIWebView,简单浏览器的制作

    制作一个简单的浏览器,包含网址输入框,Search按钮,前进.回退按钮,UIWebView就这几个简单的控件. UITextField:用来输入网址: UIbuttom:实现前进,后退,搜索等功能: ...

  7. ios学习之UIWebView网页视图调整

    //先来一个可行的小Demo程序:结合searchBar的google搜索 #import <UIKit/UIKit.h> @interface ViewController : UIVi ...

  8. ios学习之UIWebView网页视图

    转载于爱德凡的百度空间,地址:http://hi.baidu.com/aidfan/item/34a720866b33cbcdef083d37 UIWebView 使用详解 一.UIWebView加载 ...

  9. Swift学习之熟悉控件

    最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...

随机推荐

  1. ASP.NET备份还原数据库

    核心技术:using System.Data.SqlClient;using System.IO;string SqlStr1 = "Server=(local);DataBase=mast ...

  2. HDU 4893 Wow! Such Sequence!(2014 Multi-University Training Contest 3)

    题意: 有三种操作: 1 x y: 表示给x位置加上y 2 x y:查询[x,y]的区间和 3 x y:将 [x,y] 区间上的数变为最接近的 Fibonacci. 思路: 1 操作按正常单调更新,区 ...

  3. async = require('async')

    var mongoose = require('mongoose'), async = require('async'); mongoose.connect('localhost', 'learn-m ...

  4. [开发笔记]-使用jquery获取url及url参数的方法

    使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下: window.location.href; 其实只是用到了javasc ...

  5. java.net.SocketException: Too many open files

    1.ps -ef|grep java 2.lsof -p 32636 3.lsof -p 20812|wc –l   这个也可以看一个进程打开的文件数 4.ulimit –a c3p0官方提供了两个参 ...

  6. DotNetBar v12.3.0.3 Fully Cracked

    PS: 博客园的程序出现问题,导致我的博客不能访问(转到登录页),而我自己由于 Cookies 问题,一直可以访问,所以一直未发现该问题. 感谢冰河之刃告知,thx! 更新信息: http://www ...

  7. jQuery 对dom的操作

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 关于dllimport的使用

    最近做一个动态加载插件的项目,插件中的dll 主要是各厂商各型号的读卡器的通用类库,stdapi.dll,WltRS.dll,有的还有进一步封装的dll,主要是为了简化通用类库的操作. 这些类库都是用 ...

  9. JS中关于 一个关于计时器功能效果的实现

    optionSearch(); function optionSearch() { //定义一个清除计时器的变量 var timer = null; //自选标题区域 $("#optiona ...

  10. 2016 - 1 - 22 HTTP(一)

    一:通过URL找到服务器   1. URL的概念: 1.1 URL全称Uniform Resource Locatior 统一资源定位符 1.2 通过一个URL就可以找到互联网上的唯一的资源. 1.3 ...