場景:快速多次點擊cell跳轉(zhuǎn)到另一個頁面宇立,另一個頁面被push多次囤萤。
原因:push后的頁面有耗時操作或者剛好push到另一個頁面時扣蜻,另一個頁面正好在reloadData卡住主線程。造成點擊cell時卡住了县貌。
解決方法:在基類導航控制器中重寫導航控制器的push方法缸夹。
#import "ZDBaseNavigationController.h"
@interface ZDBaseNavigationController ()<UINavigationControllerDelegate>
@property (nonatomic, getter=isPushing) BOOL pushing;///< 是否正在push痪寻,防止多次push同一個VC
@end
@implementation ZDBaseNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
}
#pragma mark - Push
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.isPushing) {
NSLog(@"攔截多次push同一個VC");
return;
} else {
self.pushing = YES;
}
[super pushViewController:viewController animated:animated];
}
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
self.pushing = NO;
}