1
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BaseTabBarController : UITabBarController
|
||||
@interface BaseTabBarController : UITabBarController <UITabBarControllerDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.delegate = self;
|
||||
|
||||
[self setupTabbarAppearance];
|
||||
|
||||
// 组装 4 个 Tab:首页 / 商城 / 社区 / 我的
|
||||
@@ -104,6 +106,28 @@
|
||||
return item;
|
||||
}
|
||||
|
||||
#pragma mark - UITabBarControllerDelegate
|
||||
|
||||
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
|
||||
// 已经是当前选中的 tab,直接允许(避免重复拦截)
|
||||
if (tabBarController.selectedViewController == viewController) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSUInteger index = [tabBarController.viewControllers indexOfObject:viewController];
|
||||
if (index == NSNotFound) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
// “我的” tab 默认为第 4 个(索引 3),未登录时先跳转登录页
|
||||
if (index == 3 && ![KBUserSessionManager shared].isLoggedIn) {
|
||||
[[KBUserSessionManager shared] goLoginVC];
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user