ios 底部tabbar 怎么让它默认显示某一个item

2024-12-15 09:44:16
推荐回答(1个)
回答1:

#import "SZMTabBarController.h"
#import "SZMTabBar.h"
#import "SZMHomeViewCtrl.h"
#import "SZMNavigationController.h"
#import "SZMDiscoerViewCtrl.h"
@interface SZMTabBarController ()

@end

@implementation SZMTabBarController

- (void)viewDidLoad {
[super viewDidLoad];
//初始化一个自己的tabbar
SZMTabBar *tabBar = [[SZMTabBar alloc]init];
tabBar.delegate = self;
//通过KVC去设置只读的属性
[self setValue:tabBar forKey:@"tabBar"];

//添加四个控制器
//首页
SZMHomeViewCtrl *homeCtrl = [[SZMHomeViewCtrl alloc]init];
[self addChildVc:homeCtrl title:@"首页" imageName:@"tabbar_home" selImgName:@"tabbar_home_selected"];

UITableViewController *messageCtrl = [[UITableViewController alloc]init];
[self addChildVc:messageCtrl title:@"消息" imageName:@"tabbar_message_center" selImgName:@"tabbar_message_center_selected"];
SZMDiscoerViewCtrl *discoveryCtrl = [[SZMDiscoerViewCtrl alloc]init];
[self addChildVc:discoveryCtrl title:@"发现" imageName:@"tabbar_discover" selImgName:@"tabbar_discover_selected"];
UITableViewController *profileCtrl = [[UITableViewController alloc]init];
[self addChildVc:profileCtrl title:@"我" imageName:@"tabbar_profile" selImgName:@"tabbar_profile_selected"];

}
//设置tabbar的一些属性
- (void)addChildVc:(UIViewController *)Controller title:(NSString *)title imageName:(NSString *)imgName selImgName:(NSString *)selImgName{
Controller.title = title;
Controller.tabBarItem.image = [UIImage imageNamed:imgName];
Controller.tabBarItem.selectedImage = [UIImage imageNamed:selImgName];
self.tabBar.tintColor = [UIColor orangeColor];
SZMNavigationController *navCtrl = [[SZMNavigationController alloc]initWithRootViewController:Controller];

[self addChildViewController:navCtrl];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)TabBar:(SZMTabBar *)TabBar plusBtnDidClick:(UIButton *)btn{
NSLog(@"1");
}

@end