//
// 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的更多相关文章

随机推荐

  1. 三星galaxy s4问题解决及快捷操作

    http://blog.csdn.net/pipisorry/article/details/38474827 三星galaxy s4更改锁屏方式时出现故障 屏幕锁定设置除password以外,其它锁 ...

  2. java.net.SocketException四大异常解决方案【转】

    java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...

  3. 文件写入文件分布式系统(asp.net C#)

    ) { try { System.Drawing.Image img = System.Drawing.Image.FromStream(fileData.InputStream); &&am ...

  4. Linux 下配置网卡的别名即网卡子IP的配置 转

    what 什么是ip别名?用windows的话说,就是为一个网卡配置多个ip.when 什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ho ...

  5. NopCmmerce的FakeHttpContext类

    在 Web 中进行测试驱动的开发,比较大的困难是模拟 HttpContext; 1.Nop提供了完整的FakeHttpContext实现,如图 1.FakeHttpContext的作用. 控制器进行单 ...

  6. char *a 与char a[] 的区别

    原文:http://www.cnblogs.com/kaituorensheng/archive/2012/10/23/2736069.html char *a = "hello" ...

  7. C/C++ unit testing tools (39 found)---reference

    http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...

  8. 关于mysql下hibernate实体类字段与数据库关键字冲突的问题

    好久没写了,都忘记博客了,趁着现在还在公司,写的东西是经过验证的,不是在家凭记忆力写的,正确率有保障,就说说最近遇到的一件事情吧. 以前一直用的oracle数据库,这次项目我负责的模块所在的系统是用的 ...

  9. socket通信简介

    转:http://blog.csdn.net/xiaoweige207/article/details/6211577 “一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的 ...

  10. IOS开发 xcode报错之has been modified since the precompiled header was built

    转载的文章  很实用 IOS开发xcode报错之has been modified since the precompiled header was built 今天做百度地图的时候第一次发现下面错误 ...