美文网首页
ios 卡顿,push多次同一个页面

ios 卡顿,push多次同一个页面

作者: 架构师的一小步 | 来源:发表于2019-08-07 16:20 被阅读0次

    推荐文章,转自: https://blog.csdn.net/ds1919/article/details/51252551

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

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

    解决方法:

    重写导航控制器的push方法。

    #import "DemoNavViewController.h"
     
     
    @interface DemoNavViewController () <UINavigationControllerDelegate>
    // 记录push标志
    @property (nonatomic, getter=isPushing) BOOL pushing;
     
    @end
     
     
    @implementation DemoNavViewController
     
     
    - (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
    

    版权声明:本文为CSDN博主「ds1919」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/ds1919/article/details/51252551

    相关文章

      网友评论

          本文标题:ios 卡顿,push多次同一个页面

          本文链接:https://www.haomeiwen.com/subject/syfadctx.html