UI1_UITabBarController
//
// AppDelegate.h
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import <CoreData/CoreData.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate> @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext;
- (NSURL *)applicationDocumentsDirectory; @end //
// AppDelegate.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "LimitViewController.h" //限免
#import "FreeViewController.h" //免费
#import "ReduceViewController.h"//降价
#import "SubjectViewController.h"//专题
#import "HotHankViewController.h"//热榜
#import "AccountViewController.h"//账户
#import "SystemViewController.h" //系统 @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//标签栏控制器
//通常在一个工程中只有一个标签栏控制器, 标签控制器作为window的根视图控制器 LimitViewController *limitVC = [[LimitViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:limitVC]; //标签栏的标题 //nav1.tabBarItem.title = @"XXX";
//nav1.navigationItem.title = @"限免";
//设置title 同时设置tabBarItem.title 和 navigationItem.title
nav1.title = @"限免";
NSLog(@"title = %@ title = %@", nav1.tabBarItem.title, nav1.title);
//NSLog(@"title = %@ title = %@", nav1.title,nav1.navigationItem.title);
//NSLog(@"%p %p", nav1.tabBarItem.title, nav1.navigationItem.title); //设置选中状态的图片
nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_limitfree_press@2x"];
//设置非选中状态的图片
nav1.tabBarItem.image = [UIImage imageNamed:@"tabbar_limitfree@2x"];
nav1.tabBarItem.badgeValue = @"10"; FreeViewController *freeVC = [[FreeViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:freeVC];
nav2.title = @"免费";
nav2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_appfree_press@2x"];
nav2.tabBarItem.image = [UIImage imageNamed:@"tabbar_appfree@2x"];
//设置微标
nav2.tabBarItem.badgeValue = @"5"; ReduceViewController *reduceVC = [[ReduceViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:reduceVC];
nav3.title = @"降价"; UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"降价" image:[UIImage imageNamed:@"tabbar_reduceprice@2x"] selectedImage:[UIImage imageNamed:@"tabbar_reduceprice_press@2x"]];
nav3.tabBarItem = item3; SubjectViewController *subjectVC = [[SubjectViewController alloc] init];
subjectVC.title = @"专题"; UITabBarItem *item4 = [[UITabBarItem alloc] initWithTitle:@"专题" image:[UIImage imageNamed:@"tabbar_subject@2x"] selectedImage:[UIImage imageNamed:@"tabbar_subject_press@2x"]];
subjectVC.tabBarItem = item4; HotHankViewController *hotHankVC = [[HotHankViewController alloc] init];
hotHankVC.title = @"热榜";
UITabBarItem *item5 = [[UITabBarItem alloc] initWithTitle:@"热榜" image:[UIImage imageNamed:@"tabbar_rank@2x"] tag:0];
hotHankVC.tabBarItem = item5;
hotHankVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_rank_press@2x"]; AccountViewController *accountVC = [[AccountViewController alloc] init];
accountVC.title = @"账户"; accountVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_account@2x"];
accountVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_account_press@2x"]; SystemViewController *systemVC = [[SystemViewController alloc] init];
//创建系统样式的tabBarItem
UITabBarItem *item6 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
systemVC.tabBarItem = item6;
systemVC.title = @"书签";
//NSLog(@"system = %@",systemVC.title); UITabBarController *tabController = [[UITabBarController alloc] init]; NSArray *controllers = [NSArray arrayWithObjects:nav1,nav2,nav3,subjectVC,hotHankVC,accountVC,systemVC, nil];
tabController.viewControllers = controllers; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *titles = [defaults objectForKey:@"titles"];
NSMutableArray *newViewControllers =[NSMutableArray array];
for (NSString *title in titles) {
for (UIViewController *obj in controllers) {
if ([title isEqualToString:obj.title]) {
[newViewControllers addObject:obj];
}
}
}
if ([newViewControllers count]) {
tabController.viewControllers = newViewControllers;
}
//设置标签栏 //设置活跃状态颜色
//tabController.tabBar.tintColor = [UIColor redColor];
NSLog(@"tabBar = %@", tabController.tabBar);
//设置tabBar的背景图片
tabController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_bg@2x"];
//选中状态的指示图
//tabController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"002"];
//设置默认选中状态
tabController.selectedIndex = 1; defaults = [NSUserDefaults standardUserDefaults];
NSInteger index = [defaults integerForKey:@"selected"];
if (index) {
tabController.selectedIndex = index;
}
else
{
tabController.selectedIndex = 0;
} //tabController.selectedViewController = subjectVC;
//设置代理
tabController.delegate = self; //标签栏控制器作为window的根视图控制
self.window.rootViewController = tabController;
// tabController.tabBar.hidden=YES; return YES;
} #pragma mark ---tabBarControllerDelegate--- //点击tabBarItem调用此方法
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
NSLog(@"shouldSelect!!!"); return YES;
}
//选中tabBarItem调用此方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"did select!!!"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:tabBarController.selectedIndex forKey:@"selected"];
[defaults synchronize];
} //开始编辑时调用此方法
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
NSLog(@"开始编辑");
} - (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
NSLog(@"将要结束编辑");
} - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
NSLog(@"结束编辑"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *titles = [NSMutableArray array];
for (UIViewController *obj in tabBarController.viewControllers) {
[titles addObject:obj.title];
}
[defaults setObject:titles forKey:@"titles"];
[defaults synchronize];
} - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
[self saveContext];
} #pragma mark - Core Data stack @synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; - (NSURL *)applicationDocumentsDirectory {
// The directory the application uses to store the Core Data store file. This code uses a directory named "-000phone.com.UI1_UITabBarController" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
} - (NSManagedObjectModel *)managedObjectModel {
// The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UI1_UITabBarController" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
} - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
} // Create the coordinator and store _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"UI1_UITabBarController.sqlite"];
NSError *error = nil;
NSString *failureReason = @"There was an error creating or loading the application's saved data.";
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
} return _persistentStoreCoordinator;
} - (NSManagedObjectContext *)managedObjectContext {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
if (_managedObjectContext != nil) {
return _managedObjectContext;
} NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (!coordinator) {
return nil;
}
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
return _managedObjectContext;
} #pragma mark - Core Data Saving support - (void)saveContext {
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
NSError *error = nil;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
} @end
//
// ViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "FreeViewController.h" @interface FreeViewController () @end @implementation FreeViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor cyanColor];
self.title = @"免费";
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// HiddenViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "HiddenViewController.h" @interface HiddenViewController () @end @implementation HiddenViewController - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//隐藏标签栏 必须在视图控制器加载之前设置
self.hidesBottomBarWhenPushed = YES;
}
return self;
} - (void)dealloc
{
NSLog(@"hidden dealloc");
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor purpleColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// SystemViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SystemViewController.h" @interface SystemViewController () @end @implementation SystemViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//
// AccountViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AccountViewController.h" @interface AccountViewController () @end @implementation AccountViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//
// HotHankViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "HotHankViewController.h" @interface HotHankViewController () @end @implementation HotHankViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blueColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//
// SubjectViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SubjectViewController.h" @interface SubjectViewController () @end @implementation SubjectViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. self.view.backgroundColor = [UIColor redColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//
// LimitViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "LimitViewController.h"
#import "HiddenViewController.h" @interface LimitViewController () @end @implementation LimitViewController - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.hidesBottomBarWhenPushed = NO;
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"限免"; self.hidesBottomBarWhenPushed = YES; NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[webView loadRequest:request];
[self.view addSubview:webView]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(btnClicked)];
self.navigationItem.rightBarButtonItem = item;
} - (void)btnClicked
{
HiddenViewController *hvc = [[HiddenViewController alloc] init];
hvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self.navigationController pushViewController:hvc animated:YES];
} - (void)dealloc
{
NSLog(@"dealloc");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// ReduceViewController.m
// UI1_UITabBarController
//
// Created by zhangxueming on 15/7/8.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ReduceViewController.h" @interface ReduceViewController () @end @implementation ReduceViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor];
self.title = @"降价";
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
UI1_UITabBarController的更多相关文章
随机推荐
- 编辑器TP
http://www.itshipin.com/blog/archives/category/php/thinkphp
- UIBezierPathStudyDemo
import UIKit import XCPlayground //创建view let myView = UIView(frame:CGRectMake(0, 0, 300, 200)) //实时 ...
- iOS开发——图层OC篇&UIColor深入研究(CGColor,CIColor)
UIColor深入研究(CGColor,CIColor) 由于跟人比较喜欢研究关于图层与动画方面的技术,正打算看看别人写的好东西,就遇到了好几个问题, 第一:UIClor类方法的使用 就是关于UICo ...
- cocos2dx-jsb 跨语言调用及第三方集成 - 过程记录
1:C++中调用js方法: 问题:ios中当用户通过home键将游戏转入后台时,调用js中的暂停游戏方法: AppDelegate::applicationDidEnterBackground() 和 ...
- 云服务器 ECS Linux 服务器修改时区的两种方式
在云服务器 ECS Linux 系统中,以 Centos6.5 为例,可以通过如下两种方式,修改系统时区: 可以使用命令 tzselect,修改时区.操作示例: [root@localhost ~]# ...
- Linux 2.4调度系统分析--转
http://www.ibm.com/developerworks/cn/linux/kernel/l-k24sch/index.html 杨沙洲 (pubb@163.net)国防科技大学计算机学院 ...
- DNS服务器全面解析--转
引用地址:http://pangge.blog.51cto.com/6013757/1273087 基础认知篇 DNS服务的概述 DNS是Domain Name System 的缩写,即域名系统.DN ...
- web开发下的各种下载方法
利用TransmitFile方法,解决Response.BinaryWrite下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题. 代码如下: Response.Co ...
- The calculation of GPA
Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...
- [JavaEE] applicationContext.xml配置文件使用合集
配置实例 – 1 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...