swift 防止push多次界面

场景:快速多次点击cell跳转到另一个页面,另一个页面被push多次。

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

解决方法:重写导航控制器的push方法


//  BaseNavigationViewController.swift

import UIKit

class BaseNavigationViewController: UINavigationController,UINavigationControllerDelegate {
    
    var pushing = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = nil
        self.delegate = self
    }
    
    override var preferredStatusBarStyle : UIStatusBarStyle {
        return UIStatusBarStyle.lightContent
    }

    // MARK:UINavigationControllerDelegate
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        self.pushing = false
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.pushing{
            
           return//被拦截
            
        } else {// push 控制器
            
            self.pushing = true

            super.pushViewController(viewController, animated: true)
        }
        
    }
}

 

转载请标注:https://mp.csdn.net/postedit/82868459

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值