网页视图与警告视图

新建一个基于singleView的工程,名为webView。

在ViewController.xib中添加两个按钮,并分别关联两个方法openDoc,openWeb。


新建一个objective-c class用来展现doc或者网页的内容。

放一个web View控件和一个返回按钮。


修改WebViewController.h

//

//  WebViewController.h

//  webView

//

//  Created by cloud on 13-3-27.

//  Copyright (c) 2013 cloud. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface WebViewController :UIViewController

{

   NSURL *_theURL;

   IBOutlet UIWebView *_webView;

}

- (IBAction)pressBack:(UIButton *)sender;

@property (nonatomic,retain)NSURL *theURL;

@end

修改ViewController.m

- (IBAction)openDoc:(UIButton *)sender {

    WebViewController *web=[[[WebViewControlleralloc] init] autorelease];

    web.theURL=[NSURLfileURLWithPath:[[NSBundlemainBundle] pathForResource:@"健身"ofType:@"doc"]];

    [selfpresentModalViewController:web animated:YES];

}


- (IBAction)openWeb:(UIButton *)sender {

    WebViewController *web=[[[WebViewControlleralloc] init] autorelease];

    web.theURL=[NSURLURLWithString:@"http://www.sohu.com"];

    [selfpresentModalViewController:web animated:YES];

}

修改webViewController.m

- (void)viewDidLoad

{

    [superviewDidLoad];

    // Do any additional setup after loading the view from its nib.

    NSURLRequest *req=[NSURLRequestrequestWithURL:_theURL];

    [_webViewloadRequest:req];

}

添加UIWebViewDelegate,处理失败事件

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

{

    UIAlertView *alert=[[[UIAlertViewalloc] initWithTitle:@"警告"message:[error description]delegate:nilcancelButtonTitle:@"确定"otherButtonTitles:@"不确定",nil] autorelease ];

    [alertshow];

}

ViewController.xib中新加一个按钮,测试警告框。

- (IBAction)pressAlert:(UIButton *)sender {

//    UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"警告" message:@"出错了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"不确定", nil] autorelease ];

//    [alert show];

    UIActionSheet *as=[[UIActionSheetalloc] initWithTitle:@"加载失败" delegate:nilcancelButtonTitle:@"取消"destructiveButtonTitle:@"确定"otherButtonTitles:@"张三",@"李四",@"王五",nil];

    [asshowInView:self.view];

}

源码地址:http://download.csdn.net/detail/cloud95/5187232


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值