ios--UITabBarController代理的使用
来源:互联网 发布:淘宝店粉丝怎么看 编辑:程序博客网 时间:2024/05/17 05:57
一、设置分栏控制器代理
1、设置UITabBarController代理
通过实现tabBarController的代理方法,可以监听视图控制器的切换
实践代码:
/*思路: *1.创建若干个子视图控制器(它们是并列的关系) * 1.1创建UITabBarItem实例,赋值给相应的子视图控制器(2中方法) *2.创建一个数组,将已创建的子视图控制器,添加到数组中 *3.创建UITabBarController实例 *4.tabBarController.viewControllers = viewControllers; *5.添加到window的rootViewController中(显示出来) */ homeViewController *vc1 = [[homeViewController alloc]init]; UITabBarItem *homeItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1]; vc1.tabBarItem = homeItem; //vc1.title = @"首页"; //vc1.view.backgroundColor = [UIColor redColor]; MesageViewController *vc2 = [[MesageViewController alloc]init]; UITabBarItem *msmItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2]; vc2.tabBarItem = msmItem; //vc2.title = @"新闻"; // vc2.view.backgroundColor = [UIColor blueColor]; SearchViewController *vc3 = [[SearchViewController alloc]init]; UITabBarItem *sacItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:3]; vc3.tabBarItem = sacItem; //vc3.title = @"历史"; //vc3.view.backgroundColor = [UIColor grayColor]; settingViewController *vc4 = [[settingViewController alloc]init]; UITabBarItem *setItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMore tag:4]; vc4.tabBarItem = setItem; //vc4.title = @"搜索"; //vc4.view.backgroundColor = [UIColor yellowColor]; NSArray *viewControllers = @[vc1,vc2,vc3,vc4];//把他们放在数组中 UITabBarController *tabBarController = [[UITabBarController alloc]init]; //初始化 tabBarController.delegate = self; //设置代理 [tabBarController setViewControllers:viewControllers animated:YES]; self.window.rootViewController = tabBarController; return YES; //标志位(flag)}#pragma mark - TabBarController Delegate- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{ NSLog(@"shouldSelectViewController"); return YES;} //视图将要切换是调用,viewController为将要显示的控制器- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ NSLog(@"didSelectViewController"); //视图已经切换后调用,viewController 是已经显示的控制器}
0 0
- ios--UITabBarController代理的使用
- IOS关于UITabBarController的使用
- UITabBarController常见代理方法的使用
- 【iOS开发】---- UITabBarController的使用详解
- iOS之UINavigationController与UITabBarController的使用
- iOS UINavigationController与UITabBarController的组合使用
- iOS UINavigationController与UITabBarController的组合使用
- iOS UINavigationController与UITabBarController的组合使用
- ios--UITabBarController的用法
- ios开发--UITabBarController使用详解
- ios开发--UITabBarController使用详解
- iOS 代理的使用
- iOS 代理的使用
- iOS代理的使用
- IOS 代理的使用
- 【iOS】UIViewController、UINavigationController与UITabBarController的整合使用
- IOS UINavigationController UITabBarController嵌套使用的时候显示消息数量
- 【iOS】UIViewController、UINavigationController与UITabBarController的整合使用
- Just Sort It(快速排序)
- exec函数簇理解
- 【Game】组合游戏入门
- Call to undefined function mb_detect_encoding() 错误
- 线段树总结
- ios--UITabBarController代理的使用
- WP_Query的使用方法
- python使用pygal进行绘制数据图表和监控图表
- reinterpre_cast用法
- 探空火箭设计感想
- lua coroutine & skynet
- Fragment使用及生命周期
- wordpress调用指定分类文章
- HTTP 协议详解1