• iOS开发~防止navigation多次push一个页面


    在点击push下一个页面时,因为各种原因,点一下cell或按钮没有响应,用户可能就多点几下,这时候会打开好几个一样的页面。

    这是因为push后的页面有耗时操作或者刚好push到另一个页面时,另一个页面正好在reloadData卡住主线程。造成点击cell时卡住了。

    这时,我们可以通过重写导航控制器的方法来解决这个问题。


    #import <UIKit/UIKit.h>

    @interface NaviViewController : UINavigationController

    @end


    #import "NaviViewController.h"

    @interface NaviViewController ()<UINavigationControllerDelegate>
    // 记录push标志
    @property (nonatomic, getter=isPushing) BOOL pushing;
    @end

    @implementation NaviViewController

    - (void)viewDidLoad {
    [super viewDidLoad];

    self.delegate = self;
    }


    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.pushing == YES) {
    NSLog(@"被拦截");
    return;
    } else {
    NSLog(@"push");
    self.pushing = YES;
    }

    [super pushViewController:viewController animated:animated];
    }


    #pragma mark - UINavigationControllerDelegate
    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    self.pushing = NO;
    }
    @end

  • 相关阅读:
    PDF上添加水印
    java调用POI读取Excel
    搭建Linux的VMware Workstation Pro
    js中两种定时器的设置及清除
    SUI使用经验
    List集合与Array数组之间的互相转换
    jquery操作select
    jquery操作CheckBox
    时间格式
    java 获取路径的各种方法
  • 原文地址:https://www.cnblogs.com/huangzs/p/11719929.html
Copyright © 2020-2023  润新知