博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分栏控制器
阅读量:5138 次
发布时间:2019-06-13

本文共 6968 字,大约阅读时间需要 23 分钟。

1 //  2 //  AppDelegate.m  3 //  TabBarApp  4 //  5 //  Created by wky on 06/10/2017.  6 //  Copyright © 2017 vector. All rights reserved.  7 //  8   9 #import "AppDelegate.h" 10 #import "VCFirst.h" 11 #import "VCSecond.h" 12 #import "VCThird.h" 13  14 @interface AppDelegate () 15  16 @end 17  18 @implementation AppDelegate 19  20  21 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 22     // Override point for customization after application launch. 23      24     self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; 25  26     [self.window makeKeyAndVisible]; 27  28     VCFirst* vcFirst = [[VCFirst alloc]init]; 29      30     vcFirst.view.backgroundColor = [UIColor orangeColor]; 31      32     VCSecond* vcSecond = [[VCSecond alloc]init]; 33      34     vcSecond.view.backgroundColor = [UIColor greenColor]; 35      36     VCThird* vcThird = [[VCThird alloc ]init]; 37      38     vcThird.view.backgroundColor = [UIColor grayColor]; 39      40     vcFirst.title = @"1"; 41     vcSecond.title = @"2"; 42     vcThird.title = @"3"; 43      44     //创建分栏控制器 45     UITabBarController* tbController = [[UITabBarController alloc]init]; 46      47     //创建一个视图数组 48     NSArray* arrayVC = [NSArray arrayWithObjects:vcFirst,vcSecond,vcThird, nil]; 49     //给分栏控制器视图赋值 50     tbController.viewControllers = arrayVC; 51      52     //将分栏控制器视图作为根控制器视图 53     self.window.rootViewController = tbController; 54      55      56      57      58      59     return YES; 60 } 61  62  63 - (void)applicationWillResignActive:(UIApplication *)application { 64     // 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. 65     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 66 } 67  68  69 - (void)applicationDidEnterBackground:(UIApplication *)application { 70     // 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. 71     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 72 } 73  74  75 - (void)applicationWillEnterForeground:(UIApplication *)application { 76     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 77 } 78  79  80 - (void)applicationDidBecomeActive:(UIApplication *)application { 81     // 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. 82 } 83  84  85 - (void)applicationWillTerminate:(UIApplication *)application { 86     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 87     // Saves changes in the application's managed object context before the application terminates. 88     [self saveContext]; 89 } 90  91  92 #pragma mark - Core Data stack 93  94 @synthesize persistentContainer = _persistentContainer; 95  96 - (NSPersistentContainer *)persistentContainer { 97     // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. 98     @synchronized (self) { 99         if (_persistentContainer == nil) {100             _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"TabBarApp"];101             [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {102                 if (error != nil) {103                     // Replace this implementation with code to handle the error appropriately.104                     // 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.105                     106                     /*107                      Typical reasons for an error here include:108                      * The parent directory does not exist, cannot be created, or disallows writing.109                      * The persistent store is not accessible, due to permissions or data protection when the device is locked.110                      * The device is out of space.111                      * The store could not be migrated to the current model version.112                      Check the error message to determine what the actual problem was.113                     */114                     NSLog(@"Unresolved error %@, %@", error, error.userInfo);115                     abort();116                 }117             }];118         }119     }120     121     return _persistentContainer;122 }123 124 #pragma mark - Core Data Saving support125 126 - (void)saveContext {127     NSManagedObjectContext *context = self.persistentContainer.viewContext;128     NSError *error = nil;129     if ([context hasChanges] && ![context save:&error]) {130         // Replace this implementation with code to handle the error appropriately.131         // 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.132         NSLog(@"Unresolved error %@, %@", error, error.userInfo);133         abort();134     }135 }136 137 @end
1 // 2 //  VCFirst.m 3 //  TabBarApp 4 // 5 //  Created by wky on 06/10/2017. 6 //  Copyright © 2017 vector. All rights reserved. 7 // 8  9 #import "VCFirst.h"10 11 @interface VCFirst ()12 13 @end14 15 @implementation VCFirst16 17 - (void)viewDidLoad {18     [super viewDidLoad];19     // Do any additional setup after loading the view.20     21     UITabBarItem* tabBarItem =  [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:22];22     23     //右上角提示信息24     tabBarItem.badgeValue = @"21";25     self.tabBarItem = tabBarItem;26     27 }28 29 - (void)didReceiveMemoryWarning {30     [super didReceiveMemoryWarning];31     // Dispose of any resources that can be recreated.32 }33 34 /*35 #pragma mark - Navigation36 37 // In a storyboard-based application, you will often want to do a little preparation before navigation38 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {39     // Get the new view controller using [segue destinationViewController].40     // Pass the selected object to the new view controller.41 }42 */43 44 @end

 

转载于:https://www.cnblogs.com/vector11248/p/7631610.html

你可能感兴趣的文章
css3 导入字体
查看>>
python-requests
查看>>
Selenium-一组元素的定位
查看>>
oracle课堂随笔--第十四天
查看>>
设计一个应用或网站时的流程
查看>>
mac安装配置mysql
查看>>
BZOJ 1011: [HNOI2008]遥远的行星
查看>>
WCF-绑定模型(一)
查看>>
Codeforces-A. Shortest path of the king(简单bfs记录路径)
查看>>
POJ--3279(开关问题2个不同时间写的代码)
查看>>
Leetcode: Combination Sum IV && Summary: The Key to Solve DP
查看>>
2015年九月八日---js学习总结
查看>>
VB6多线程,关键段操作
查看>>
Android LayoutInflater 使用[常用于自定义视图,UI件]
查看>>
Jquery解析json数组字符串
查看>>
centos7网卡报错,ip地址丢失不见等问题解决方法
查看>>
angular2/angular4 如何通过$http的post方法请求下载二进制的Excel文件
查看>>
从产品展示页面谈谈Hybris系列之二: DTO, Converter和Populator
查看>>
Windows下使用python库 curses遇到错误消息的解决方案
查看>>
layer.js打印iframe方法
查看>>