//
// 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. busybox配置telnetd

    busybox配置telnetd的问题 进入busybox源码文件夹,选择telnet,telnetd.后确保在ramdisk的sbin文件夹下存在inetd和in.telnetd或telned.在r ...

  2. 在XAF应用程序使用现有的数据库?

    https://documentation.devexpress.com/#Xaf/CustomDocument3061

  3. Android Task 与 Back Stack

    Tasks and Back Stack 一个应用通常包括多个 activity.每个 activity应用设计为围绕针对执行用户特定的行为和可以启动其它 activity. 一个 Activity也 ...

  4. iOS开发——测试篇&breakpoints、lldb 和 chisel 的详解

    breakpoints.lldb 和 chisel 的详解 Breakpoints BreakPoint分类 breakpoint也是有分类的,我这里的文章内大致按使用的方式分为了 Normal Br ...

  5. JavaScript跨域实现

    最近在做个上传文件的服务,其中包含一个上传的web页面.目的是想客户端页面嵌套这个web页面,然后直接将文件上传到服务器. 因为文件不同所以需要保存到的文件夹名称也不一样,所以客户端需要传递一个文件夹 ...

  6. 数据结构之平衡二叉树(AVL)

    一:平衡二叉树特点:平衡二叉树(Balanced binary tree)是由阿德尔森-维尔斯和兰迪斯(Adelson-Velskii and Landis)于1962年首先提出的,所以又称为AVL树 ...

  7. MTD NANDFLASH驱动相关知识介绍

    转:http://blog.csdn.net/zhouzhuan2008/article/details/11053877 目录 MTD总概述 MTD数据结构 MTD相关层实现 MTD,Memory ...

  8. Timed Code

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  9. 通用权限底层研究:Web应用限制IP访问的功能实现

    如果你的web应用受到恶意扫描或攻击,你会怎么处理呢?大多数时候从应用日志里可以看到恶意扫描或攻击,遇到此类情况,如有一个可以进行IP访问控制的功能就好些了. 现将在MVC下实现的一个IP访问限制功能 ...

  10. FormsAuthentication与Session超时时间不一的解决方法

    因为FormsAuthentication 和 Session 的cookies不一样,造成了FormsAuthentication 还能进入,而 session已经超时的问题. 最好的办法就是当让F ...