首页 > UITabBarController在UIViewController下运行问题?

UITabBarController在UIViewController下运行问题?

在.h文件下

import <UIKit/UIKit.h>

import "IndexViewController.h"

import "MessageViewController.h"

import "SearchViewController.h"

import "UserInfoViewController.h"

@interface MainViewController : UIViewController
{
UITabBarController *tab;
}
-(void)checkController;

@end

在MainViewController.m文件下
图片上传不了,,所以就复制了,,
- (void)checkController{

IndexViewController *index=[[IndexViewController alloc]init];
UINavigationController *nav_index=[[UINavigationController alloc]initWithRootViewController:index];
nav_index.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"主页" image:[UIImage imageNamed:@"btn_maintab_home_nor"] selectedImage:[UIImage imageNamed:@"btn_maintab_home_press"]];

SearchViewController *search=[[SearchViewController alloc]init];
UINavigationController *nav_search=[[UINavigationController alloc]initWithRootViewController:search];
nav_search.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"发现" image:[UIImage imageNamed:@"btn_maintab_explore_nor"] selectedImage:[UIImage imageNamed:@"btn_maintab_explore_press"]];

MessageViewController *message=[[MessageViewController alloc]init];
UINavigationController *nav_message=[[UINavigationController alloc]initWithRootViewController:message];
nav_message.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"btn_maintab_message_nor"] selectedImage:[UIImage imageNamed:@"btn_maintab_message_press"]];
//性别有异
UserInfoViewController *userInfo=[[UserInfoViewController alloc]init];
UINavigationController *nav_userInfo=[[UINavigationController alloc]initWithRootViewController:userInfo];
nav_userInfo.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"我" image:[UIImage imageNamed:@"btn_maintab_me_male_nor"] selectedImage:[UIImage imageNamed:@"btn_maintab_me_male_press"]];

tab=[[UITabBarController alloc]init];
tab.viewControllers=[NSArray arrayWithObjects:nav_index,nav_search,nav_message,nav_userInfo, nil];

tab.delegate = self;


[self.view addSubview:tab.view];

}

主要代码是以上这些:
在3.5英寸模拟器下运行的结果是:


MainViewController是根视图控制器
背景颜色为绿色
tab不是在底部的吗?
诚心请教各位大神为什么会是这样的结果?

【热门文章】
【热门文章】