UITabBarController
来源:互联网 发布:嗨森矩阵 编辑:程序博客网 时间:2024/05/23 21:09
//// MainViewController.m// AppUI组件学习//// Created by 麦子 on 15/6/19.// Copyright (c) 2015年 麦子. All rights reserved.//#import "MainViewController.h"#import "MyNavigationViewController.h"#import "TableViewController.h"#import "DataViewController.h"#import "NetWorkViewController.h"#import "RootViewController.h"#import "MyDemoUIViewController.h"#import "NavigationDemoRootViewController.h"@interface MainViewController (){ RootViewController *root; MyNavigationViewController *uiView; TableViewController *tableView ; NetWorkViewController *netWorkView; DataViewController *dataView; NSUserDefaults *userMessage; MyDemoUIViewController *demoUI; NavigationDemoRootViewController *navigationDemo; }@end/*** 其中组件相互独立, 每一个的生命周期都是和TabBarViewController一致,没显示的也只是挂起状态,没有销毁。 */@implementation MainViewController- (void)viewDidLoad { userMessage = [NSUserDefaults standardUserDefaults]; [super viewDidLoad]; [self creatView]; [self updateTabBarUiView]; [self deleteStu];// self.tabBar.hidden = true;//隐藏tabBar,自定义TabBar [self createMyTabBar];}- (void)creatView{ root = [[RootViewController alloc] init]; navigationDemo = [[NavigationDemoRootViewController alloc] init]; uiView = [[MyNavigationViewController alloc] initWithRootViewController:navigationDemo]; // uiView = [[MyNavigationViewController alloc] initWithRootViewController:root]; demoUI = [[MyDemoUIViewController alloc] init]; tableView = [[TableViewController alloc] init]; dataView = [[DataViewController alloc] init]; netWorkView = [[NetWorkViewController alloc] init]; // 自动创建TabBarItem,如果是用系统的,那么其他的都是没有效果的。 UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:200]; tableView.tabBarItem = item; demoUI.tabBarItem.title = @"demoUI"; [netWorkView.tabBarItem initWithTitle:@"网络" image:[UIImage imageNamed:@"tupian5.jpg"] selectedImage:[UIImage imageNamed:@"tupian4.jpg"]]; NSArray *array = [NSArray arrayWithObjects:uiView,demoUI,tableView,dataView,netWorkView,nil]; self.viewControllers = array; // moreNavigationController 不会在 viewControlers中,他是单独来处理的。// self.moreNavigationController // 设置选中第几个 long index = [userMessage integerForKey:@"index"]; self.selectedIndex = index; [self tabbarCallMethods]; }// tabBarItem常用属性- (void)updateTabBarUiView{ uiView.tabBarItem.title = @"UI组件"; uiView.tabBarItem.badgeValue = @"10"; uiView.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -10); tableView.tabBarItem.title = @"表视图"; dataView.tabBarItem.title = @"数据";}/***tabBar常用属性*/- (void)tabbarCallMethods{ /** items,selectedItem 属性是由tabController来管理的,不能对他进行外部的付值, */// self.tabBar.items = [NSArray arrayWithObjects:tableView.tabBarItem, nil];// self.tabBar.selectedItem = tableView.tabBarItem; self.tabBar.backgroundColor = [UIColor yellowColor];// self.tabBar.backgroundImage = [UIImage imageNamed:@"tupian3.jpg"]; // 改变选中图片的色调// self.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"tupian3.jpg"]; // 改变选中图片的色调 self.tabBar.tintColor = [UIColor blueColor];}/**自定义TabBar*/- (void)createMyTabBar{ }/** 常用代理 **/- (void)deleteStu{ self.delegate = self;}#pragma mark---#pragma mark delegate/** 是否允许点击Item, YES表示可以点击, NO表示不可以点击 */- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{// if (viewController.tabBarItem.tag == 200) {// return NO;// } return YES;}/*** 每次点击都会触发 */- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ NSArray *array = tabBarController.viewControllers; int index = 0; for (int i = 0; i < [array count]; i++) { if (viewController == [array objectAtIndex:i]) { index = i; break; } } [userMessage setObject:[NSNumber numberWithInt:index] forKey:@"index"]; [userMessage synchronize]; // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"Item被点击了" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];// [alert show];}/*** 点击更多里面的编辑按钮的时候调用 */- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"修改按钮被点击了" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil]; [alert show]; NSLog(@"%@",viewControllers);// 所有的ViewController}/*** 点击完成后,调用, viewControllers 这个事最新的排练方式 */- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{ UIAlertView *alert = nil; if (changed) { alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"顺序被修改了" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil]; }else{ alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"没有任何操作了" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil]; } [alert show];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }@end
0 0
- UITabbarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabbarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabbarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- UITabBarController
- 体系结构复习3——数据级并行
- 使用Spring MVC 4构建Restful服务 搭建Spring MVC 4开发环境八步走
- 黑马程序员_JAVA的构造方法
- 第15周项目1-用二进制文件处理学生成绩
- mac 递归删除文件路径 find . -name ._*|xargs rm -rf
- UITabBarController
- java大型企业级互联网框架平台 SpringMVC Mybatis Shiro Bootstrap
- Mahout安装与第一次使用--用户协同过滤
- AOP
- 数据仓库工作总结(觉得有点意思)
- 不要在析构函数中抛出异常
- JAVA 企业级框架、安全权限、高并发、多线程、稳定强
- Error:No suitable device found: no device found for connection "System eth0"
- android开发网络请求的几种方法