多次点击TableViewCell重复触发push的解决方案

齐建安
2023-12-01
  • 给NavigationController一个标签push属性记录控制器的push转态。

  • 在自定义的NIPNavigationController的方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated拦截是否正在push,如果是在push就直接return,否则跳转过来。

  • 在代理方法- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated该方法执行标志着push成功,成功之后重置push标签NO。

少BB直接上代码:


@interface NIPNavigationController ()<UINavigationControllerDelegate>
// 记录push转态
@property (nonatomic, assign,getter=isPushing) BOOL pushing;
@end

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.isPushing == YES) {
        return;
    }else{
        self.pushing = YES;
    }
    [super pushViewController:viewController animated:animated];
}

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


 

 类似资料: