zoukankan      html  css  js  c++  java
  • UIWebView页面的控制(二)

    1.UIWebView的内容控制的属性/方法列表

    loading属性               确认当前页面是否在读入中

    canGoForward属性   确认goForward  方法是否可运行,可运行为yes;

    canGoBack属性        确认goBack  方法是否可运行,可运行为yes。

    goBack方法               返回前一个页面

    goForword方法          进入下一个页面

    reload方法                 又一次读入当前页

    stopLoading方法       中止当前页的读入

    2.webViewController.h

    @interface webViewController : UIViewController<UIWebViewDelegate,UINavigationControllerDelegate,UINavigationBarDelegate>
    {
        UIWebView *_webView;
    }
    
    @property(nonatomic,strong)UIBarButtonItem *reloadButton;
    @property(nonatomic,strong)UIBarButtonItem *stopButton;
    @property(nonatomic,strong)UIBarButtonItem *backButton;
    @property(nonatomic,strong)UIBarButtonItem *forwardButton;
    @end


    webViewController.m


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.navigationItem.title = @"UIWebView測试版";
        _webView = [[UIWebView alloc]init];
        _webView.delegate = self;
        _webView.frame = self.view.frame;
        _webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        _webView.scalesPageToFit = YES;
        [self.view addSubview:_webView];
        //工具条中追加按钮
        _reloadButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadDidPush)];
        _stopButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action: @selector(stopDidPush)];
        _backButton = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(backDidPush)];
        _forwardButton = [[UIBarButtonItem alloc]initWithTitle:@"Forward" style:UIBarButtonItemStyleBordered target:self action:@selector(forwardDidPush)];
        NSArray *buttons = [NSArray arrayWithObjects:_backButton,_forwardButton,_reloadButton,_stopButton, nil];
       [self setToolbarItems:buttons animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
        
    
    }
    -(void)reloadDidPush
    {
        [_webView reload];//又一次读入页面
    }
    -(void)stopDidPush
    {
        if(_webView.loading){
            [_webView stopLoading];//读入停止
        }
        
    }
    -(void)backDidPush
    {
        if (_webView.canGoBack) {
            [_webView goBack];//返回前一画面
        }
    }
    -(void)forwardDidPush
    {
        if (_webView.canGoForward) {
            [_webView goForward];//进入下一页面
        }
        
    }
    
    -(void)updateControlEnabled
    {
        //统一更新指示按钮状态
        [UIApplication sharedApplication].networkActivityIndicatorVisible = _webView.loading;
        _stopButton.enabled = _webView.loading;
        _backButton.enabled = _webView.canGoBack;
        _forwardButton.enabled = _webView.canGoForward;
        
    }
    -(void)viewDidAppear:(BOOL)animated
    
    {
        //画面显示结果后读入web页面画面
        [super viewDidAppear:animated];
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
        [_webView loadRequest:request];
        [self updateControlEnabled];
    }
    -(void)viewWillDisappear:(BOOL)animated
    {
        //画面关闭时状态的活动指示器设置成off
        [super viewWillDisappear:animated];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }
    
    -(void)webViewDidStartLoad:(UIWebView *)webView{
        [self updateControlEnabled];
    }
    
    -(void)webViewDidFinishLoad:(UIWebView *)webView
    
    {
        [self updateControlEnabled];
    }
    -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    {
        [self updateControlEnabled];
    }
    



  • 相关阅读:
    介绍一款jquery ui组件gijgo(含tree树状结构、grid表格),特点:简易、文档全清晰易懂、示例代码
    【未完待续】API接口
    表单中Readonly和Disabled的区别:readonly在get和post可传值到后端,disabled不可
    Newtonsoft.Json 转换DateTime类型为字符串时,串内部会有一个T。解决方案
    一种历史详细记录表,完整实现:CommonOperateLog 详细记录某用户、某时间、对某表、某主键、某字段的修改(新旧值
    js return falsee.preventDefault() 以及session
    bootstrape学习
    Redis的PHP操作手册
    PHP表单常用正则表达式(URL、HTTP、手机、邮箱等)
    大型网站架构演化
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6726105.html
Copyright © 2011-2022 走看看