iPhone/iOS UIViewController之UITabBarController
来源:互联网 发布:佳能ip1180打印机端口 编辑:程序博客网 时间:2024/05/21 10:56
一.TabBarController的主要参数以及结构
主要参数有
viewControllers: tab bar statck
customizableViewController: custom一部分tabbarItem
selectedViewController:当前选择中的viewController
moreNavigationController:当tabbarItem过多,系统则会自动生成一个更多的item,可以通过该参数获得所需要的信息
二.创建Tab Bar,管理显示tab bar items
1.代码方式创建
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[FCDemoViewController alloc] initWithNibName:@"FCDemoViewController" bundle:nil] autorelease]; FirstViewController *first= [[FirstViewController alloc]init]; first.tabBarItem.title=@"first"; first.tabBarItem.image=[UIImage imageNamed:@"1.jpg"]; //也可以用下面方式声明barItem UITabBarItem* itm=[[UITabBarItem alloc]initWithTitle:@"first" image:[UIImage imageNamed:@"1.jpg"] tag:2000]; first.tabBarItem=itm; first.tabBarItem.badgeValue=@"a"; self.viewController.tabBarItem.title=@"root"; self.viewController.tabBarItem.image=[UIImage imageNamed:@"book-prev1.png"]; UITabBarController *tab=[[UITabBarController alloc]init]; tab.viewControllers=[NSArray arrayWithObjects:self.viewController,first, nil]; self.window.rootViewController = tab; [self.window makeKeyAndVisible];
同样可以用nib
2.运行时管理tabbar
-(void) setViewControllers:animated;
3.禁止某个tab选中
设置tabBarController的delegate对象,并且实现-(BOOL)tabBarController:shouldSelectViewController:方法,返回no则当前这个选择无效。
下面代码是个登录界面,在没有登录成功情况下,只有点击第一个tab是有效的
- (IBAction)processUserInformation:(id)sender{ // Call some app-specific method to validate the user data. // If the custom method returns YES, remove the tab. if ([self userDataIsValid]) { NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; [newArray removeObject:self]; [self.tabBarController setViewControllers:newArray animated:YES]; }}
4.跟踪tab变化的方法
设置tabBarController的delegate,delegate实现UITabBarControllerDelegate协议
5.tab右上角的提示
badgeValue:右上角一个提示的文字,吸引用户来点击
- iPhone/iOS UIViewController之UITabBarController
- iPhone/iOS UIViewController之UINavigationController
- iPhone/iOS UIViewController之UINavigationController
- IOS之UIViewController、UINavigationController与UITabBarController的整合使用
- iPhone/iOS UIViewController之UIPageViewController(iOS5 only)
- iphone--UIViewController/UITabBarController和UINavigationController的结合
- IOS 从UIViewController跳转到UITabBarController
- iphone ios UITabBarController 切换动画
- iphone ios UITabBarController 切换动画
- Different display with UIViewController add UITabBarController between iphone and ipad
- iOS应用之UITabBarController
- iOS开发之UITabBarController
- iOS开发之UITabBarController
- IOS之UITabBarController
- 【iOS】UIViewController、UINavigationController与UITabBarController的整合使用
- 【iOS】UIViewController、UINavigationController与UITabBarController的整合使用
- 纯代码搭建iOS三级结构(UITabbarController+UINavigationController+UIViewController)
- iOS开发之UIViewController
- 系统的程序有问题怎么办
- 复习struts2之自定义类型转换器
- 如何建立家庭局域网?
- 将坐标集合datatable 存为googleearth可打开的kml文件
- 不插usb声卡时,录像机无法关闭
- iPhone/iOS UIViewController之UITabBarController
- 层次聚类算法
- android 如何获取launcher的workspace中的每一个celllayout的位图???
- Myeclipse 默认字符集设置
- spring源码学习笔记-初始化(二) PostProcessor
- 《浅谈VC++工程的文件组织》关于VS的IDE的转载
- 《#诗盗#·快撸》
- 暂无
- CDC的几种用法