多次點擊TableViewCell重複觸發push的解決方案

原文鏈接:https://www.jianshu.com/p/197817a36070
  • 給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;
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章