1、简单实现

效果:在视图底部显示一个工具栏

代码实现

// 创建窗口

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

// 指定跟控制器

UITabBarController *tabBar = [[UITabBarController alloc] init];

self.window.rootViewController = tabBar;

UIViewController *vc1 = [[UIViewControlleralloc] init];

[tabBar addChildViewController:vc1];

vc1.view.backgroundColor = [UIColorredColor];

vc1.tabBarItem.title  = @"聊天";

vc1.tabBarItem.image = [UIImage imageNamed:@“tab_recent_nor"];

UIViewController *vc2 = [[UIViewControlleralloc] init];

[tabBar addChildViewController:vc2];

vc2.view.backgroundColor = [UIColorgreenColor];

vc2.tabBarItem.title  = @"空间";

vc2.tabBarItem.image = [UIImage imageNamed:@“tab_qworld_nor"];

UIViewController *vc3 = [[UIViewControlleralloc] init];

[tabBar addChildViewController:vc3];

vc3.view.backgroundColor = [UIColorgreenColor];

vc3.tabBarItem.title  = @"联系人";

vc3.tabBarItem.image = [UIImage imageNamed:@“tab_buddy_nor"];

UIViewController *vc4 = [[UIViewControlleralloc] init];

[tabBar addChildViewController:vc4];

vc4.view.backgroundColor = [UIColorgreenColor];

vc4.tabBarItem.title  = @"设置";

vc4.tabBarItem.image = [UIImage imageNamed:@“tab_me_nor"];

vc4.tabBarItem.badgeValue = @“10”; // 右上角显示数字

// 显示窗口

[self.windowmakeKeyAndVisible];

综合使用

UITabBarController的使用

一般是一个UITabBarController控制多个NavigationController,这样可以保证每一个控制器下都有一个单独的顶部导航栏,而不是整个应用只有一个导航栏。

比如下面这个界面,一个UITabBarController控制多个NavigationController,然后有NavigationController控制界面内部的跳转。

 

类似效果如下:

主界面有三个TableView组成,通过tabBarController进行控制。

在聊天界面选中cell后跳转到下一个控制器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

UIStoryboard *story = [UIStoryboardstoryboardWithName:@"Main"bundle:nil] ;

SLQChatViewController *chat = [story instantiateViewControllerWithIdentifier:@"chat"];

// 选中cell后跳转到chat界面

[self.navigationControllerpushViewController:chat animated:YES];

}

          

在设置界面的关于条目通过拖线建立与关于控制器的跳转。

注意情况

主要是各种cell的自定义方法。因为很多界面都是自定义的cell组成的。

还有就是从storyboard中加载控制器进行界面的跳转

UIStoryboard *story = [UIStoryboard storyboardWithName:@“Main"bundle:nil] ;

SLQChatViewController *chat = [story instantiateViewControllerWithIdentifier:@"chat"];

// 选中cell后跳转到chat界面

[self.navigationController pushViewController:chat animated:YES];

隐藏底部导航条可以设置控制的属性

IOS笔记049-UITabBarController的更多相关文章

  1. iOS 怎么设置 UITabBarController 的第n个item为第一响应者?

    iOS 怎么设置 UITabBarController 的第n个item为第一响应者? UITabBarController 里面有个属性:selectedIndex @property(nonato ...

  2. IOS开发之UITabBarController与UINavigationController混合使用

    ios开发中UITabBarController与UINavigationController混合使用是很多app的基础页面结构,下面是简单的的页面初始化的方法,在AppDelegate.m的 - ( ...

  3. iOS开发之UITabBarController和UICollectionView的使用

    这一篇要记录的是iOS开发中UITabBarController控件和UICollectionView控件的使用.APP跑起来之后的效果例如以下图: watermark/2/text/aHR0cDov ...

  4. 荼菜的iOS笔记--UIView的几个Block动画

    前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...

  5. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  6. IOS笔记 1

    < ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...

  7. UITabBarController 笔记(三) UITabBarController 配合 UINavigationController 的使用

    建个空的iOS工程 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictiona ...

  8. 【转】iOS笔记-自定义控件(OC)

    原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...

  9. iOS笔记———数据存储

    应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...

  10. Xamarin开发IOS笔记:切换输入法时输入框被遮住

    在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...

随机推荐

  1. Yii2 Working with Relational Data at ActiveDataProvider

    Yii2 Working with Relational Data at ActiveDataProvider namespace common\models; use Yii; use yii\ba ...

  2. pta编程题5 Pop Sequence

    第一次提交结果都是YES,后来检查发现Push,Pop函数写的有问题,即Stack sta改为引用Stack &sta,否则不能改变实参的值. #include <iostream> ...

  3. go语言,第三方包相对路径导入包引起的问题及解决方案(goquery)

    对go语言而言,跟踪init很显然包有且仅有一次被导入的可能. 但是重复引用了goquery包,后编译出现问题 项目涉及相关目录 ├── main.go└── parse    └── parse.g ...

  4. SEO人士一定要了解的搜索引擎惩罚原则

       SEO人士一定要了解的搜索引擎惩罚原则 SEO 的人一般都知道SEO分为白帽,黑帽,甚至还有灰帽.简单说,如果你熟读过谷歌网站质量指南,就可以了解,符合搜索引擎质量规范并且符合用户体验的SEO ...

  5. os.walk 模块

    os.walk()可以得到一个三元tupple(dirpath, dirnames, filenames),其中第一个为起始路径,第二个为起始路径下的文件夹,第三个是起始路径下的文件. 其中dirpa ...

  6. python_23_tuple

    #元组只能统计和获取下表,不能插入之类的.元组和列表差不多,也是存一组数,只是它一旦创建,便不能再修改,所以又叫只读列表 names=('QiZhiguang','LiuGuannan','Liang ...

  7. python读取文件指定行

    import linecache file=open('3_2.txt','r') linecount=len(file.readlines()) linecache.getline('3_2.txt ...

  8. SpringBoot学习记录(一)

    一.SpringBoot入门 1.SpringBoot简介 简化Spring应用开发的一个框架:整个Spring技术栈的一个大整合:J2EE开发的一站式解决方案: SpringBoot的优点: (1) ...

  9. windows下安装win7虚拟机并安装oracle

    一.win7虚拟机 与安装linux虚拟机没有什么不同,不同的是选择客户机操作系统.内存.磁盘容量,以及映像文件. 创建win7虚拟机步骤简化: 新建虚拟机-->>自定义-->> ...

  10. Linux MySQL 修改密码

    修改root本地登录密码 修改root默认的密码(方法一)1. 启动mysql之后systemctl start mysqld.service2. 修改mysql的配置文件 vi /etc/my.cn ...