在ios中经常出现push多个相同页面,为了防止这种现象您可以如下设置
//自定义naviViewController,实现代理方法
#import "NaviViewController.h"
@interface NaviViewController () <UINavigationControllerDelegate>
// 记录push标志
@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) {
DDLogError(@"----------------------------------被拦截");
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;
}
- (void)dealloc {
self.navigationController.delegate = nil;
}
初始化tabBarController时
设置viewController的NavigationController为NaviViewController就可
MainViewController *mainVc = [[MainViewController alloc] init];
NaviViewController *nvc = [[NaviViewController alloc] initWithRootViewController:mainVc];
欢迎互相学习Github