1问题描述
由于网络请求、线程阻塞等原因,
项目当中某个页面push到下一个页面的时候,会出现多次push的问题。
2)解决方案
① 自定义BaseNavigationController,继承于UINavigationController;
②遵循代理UINavigationControllerDelegate;
③添加一个属性isPush,标识push状态;
④设置代理;
⑤重写pushViewController方法;
⑥重写didShowViewController方法;
#import "BaseNavigationController.h"
@interface BaseNavigationController ()<UINavigationControllerDelegate>
@property (nonatomic,assign)BOOL isPush;
@end
@implementation BaseNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate =self;
self.view.backgroundColor = [UIColor yellowColor];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.isPush) {
//如果已经isPush,但尚未didShow,则返回不再二次push
return;
}else{
self.isPush = YES;
}
[super pushViewController:viewController animated:animated];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
//didShow之后,重置isPush状态为NO,以达到下次可以正常push的目的;
self.isPush = NO;
}
网友评论