場景:快速多次點擊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