zoukankan      html  css  js  c++  java
  • 分栏控制器

      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 support
    125 
    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 @end
    14 
    15 @implementation VCFirst
    16 
    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 - Navigation
    36 
    37 // In a storyboard-based application, you will often want to do a little preparation before navigation
    38 - (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
  • 相关阅读:
    恢复计算机崩溃数据的五款最佳Linux发行版
    不敢想象!Vim使用者的“大脑”竟是这样
    开发者和系统管理者最喜爱的开源工具Vim 起步学习的五个技巧
    .NET程序与CA对接一直提示重定向
    覆盖原有div或者Input的鼠标移上去描述
    IOS9以上如何导入铃声并设置
    c# 动态调用webserver
    没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的
    url 参数的加号变成空格处理
    在git 服务器挂载、创建新的项目、克隆新的项目
  • 原文地址:https://www.cnblogs.com/vector11248/p/7631610.html
Copyright © 2011-2022 走看看