在点击push下一个页面时,因为各种原因,点一下cell或按钮没有响应,用户可能就多点几下,这时候会打开好几个一样的页面。
这是因为push后的页面有耗时操作或者刚好push到另一个页面时,另一个页面正好在reloadData卡住主线程。造成点击cell时卡住了。
这时,我们可以通过重写导航控制器的方法来解决这个问题。
- #import <UIKit/UIKit.h>
-
- @interface NaviViewController : UINavigationController
-
- @end
- #import "NaviViewController.h"
-
- @interface NaviViewController ()<UINavigationControllerDelegate>
-
- @property (nonatomic, getter=isPushing) BOOL pushing;
- @end
-
- @implementation NaviViewController
-
- - (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