ios - UITabBarController在UIViewController下运行问题?
高洛峰
高洛峰 2017-04-17 13:02:10
[iOS讨论组]

在.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不是在底部的吗?
诚心请教各位大神为什么会是这样的结果?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号