IOS:将viewcontroller添加到IOS中的自定义选项卡栏
我正在做一个聊天项目,在这个项目中我必须使用IOS:将viewcontroller添加到IOS中的自定义选项卡栏,ios,objective-c,uiviewcontroller,uitabbar,Ios,Objective C,Uiviewcontroller,Uitabbar,我正在做一个聊天项目,在这个项目中我必须使用uitabar。我在这个项目中使用故事板,但根据要求,我在项目中添加了自定义选项卡,将其安装在视图的顶部。 现在的问题是自定义选项卡栏在视图顶部显示良好,但当我单击选项卡时,它只显示黑屏,而不显示ViewController。 我正在分享我的代码,请给我建议解决方案 我的.h文件 @interface TabBar : UITabBarController { } @property(strong,nonatomic) UITabBarControl
uitabar
。我在这个项目中使用故事板,但根据要求,我在项目中添加了自定义选项卡,将其安装在视图的顶部。
现在的问题是自定义选项卡栏在视图顶部显示良好,但当我单击选项卡时,它只显示黑屏,而不显示ViewController。
我正在分享我的代码,请给我建议解决方案
我的.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"]];
}
输出的快照是
视图控制器的初始化似乎不正确 如果视图控制器都在情节提要中,请尝试替换
_chatlist = [ChatListVC new];
_contactlist = [ContactListVc new];
_findfriends = [FindfriendsVC new];
与:
其中,标识符字符串是您在故事板中设置的自己的标识符。看起来您的视图控制器没有正确初始化 如果视图控制器都在情节提要中,请尝试替换
_chatlist = [ChatListVC new];
_contactlist = [ContactListVc new];
_findfriends = [FindfriendsVC new];
与:
其中,标识符字符串是您在序列图像板中设置的自己的标识符。您是否已将ViewController添加到序列图像板中的Tabbarcontroller?我正在使用自定义tabbar,您的视图控制器的视图未加载。(即ChatListVC的视图未从故事板加载)是视图未加载检查Allanah Douglas给出的答案。它会起作用。您是否已将ViewController添加到序列图像板中的Tabbarcontroller?我正在使用自定义tabbar,您的视图控制器的视图未加载。(即ChatListVC的视图未从故事板加载)是视图未加载检查Allanah Douglas给出的答案。它可以工作。标识符是指情节提要id?标识符是指情节提要id?