我正在开发一个聊天项目,我必须使用UITabBar
。我在这个项目中使用故事板,但根据要求,我在项目中添加了自定义TabBar,将它安装在视图的顶部。 现在的问题是自定义TabBar显示在视图顶部,但是当我点击标签时,它只显示黑色屏幕而不是显示ViewControllers。 我分享我的代码,请建议我解决它。IOS:将viewcontroller添加到ios中的自定义TabBar
我.h文件中
@interface TabBar : UITabBarController
{
}
@property(strong,nonatomic) UITabBarController *tabbarcontroller;
@property(strong,nonatomic) ChatListVC *chatlist;
@property(strong,nonatomic) ContactListVc *contactlist;
@property(strong,nonatomic) FindfriendsVC *findfriends;
@end
我.m文件
@implementation TabBar
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// self.navigationItem.hidesBackButton=YES;
self.title = @"Chat Home Page";
self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
_chatlist = [ChatListVC new];
_contactlist = [ContactListVc new];
_findfriends = [FindfriendsVC new]; //initWithNibName:@"FindfriendsVC" bundle:nil];//[FindfriendsVC new];
self.tabbarcontroller = [[UITabBarController alloc]init];
self.viewControllers = [NSArray arrayWithObjects:_chatlist,_contactlist,_findfriends, nil];
//self.navigationController.navigationBar.frame.size.height;
//UITabBar *tabBar = self.tabBarController.tabBar;
//CGFloat topBarOffset = self.topLayoutGuide.length;
self.tabBar.frame =CGRectMake(0,44,self.view.frame.size.width,50);
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
item0.title = @"Chat List";
item1.title = @"Contacts";
item2.title = @"Find Friends";
[item0 setFinishedSelectedImage:[UIImage imageNamed:@"chatlist.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"chatlist.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"contacts.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"contacts.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"findfriends.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"findfriends.png"]];
}
您是否已将Viewcontrollers添加到Storyboard中的Tabbarcontroller中? – OMK
我在这里使用自定义标签栏 –
您的视图控制器的视图未获得加载。 (即查看ChatListVC未从Storyboard加载) – OMK