XIB使用

  1 //
  2 //  AppDelegate.m
  3 //  XIBAPP
  4 //
  5 //  Created by on 29/09/2017.
  6 //  Copyright © 2017 All rights reserved.
  7 //
  8 
  9 #import "AppDelegate.h"
 10 #import "VCRoot.h"
 11 
 12 @interface AppDelegate ()
 13 
 14 @end
 15 
 16 @implementation AppDelegate
 17 
 18 
 19 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 20     // Override point for customization after application launch.
 21     
 22     //创建一个window对象
 23     self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
 24     //获得视图控制器根节点对象
 25     //P1:要加载的XIB资源文件名,加载的XIB作为视图控制器视图
 26     //P2:是指主文件包,XIB所在的位置
 27     //mainBundle是主资源文件包,如果传nil,函数会自动到mainBundle中去找。
 28     
 29     //*******显式加载XIB文件*********
 30 //    VCRoot* root = [[VCRoot alloc] initWithNibName:@"VCRoot" bundle:[NSBundle mainBundle]];
 31 
 32     //*******隐式加载**************
 33     //如果系统中有和XIB资源文件同名的类,
 34     //那么init函数会自动加载VCRoot.xib文件
 35     
 36     VCRoot* root = [[VCRoot alloc]init];
 37     
 38     self.window.rootViewController = root;
 39     
 40     [self.window makeKeyAndVisible];
 41     
 42     
 43     return YES;
 44 }
 45 
 46 
 47 - (void)applicationWillResignActive:(UIApplication *)application {
 48     // 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.
 49     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
 50 }
 51 
 52 
 53 - (void)applicationDidEnterBackground:(UIApplication *)application {
 54     // 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.
 55     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
 56 }
 57 
 58 
 59 - (void)applicationWillEnterForeground:(UIApplication *)application {
 60     // 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.
 61 }
 62 
 63 
 64 - (void)applicationDidBecomeActive:(UIApplication *)application {
 65     // 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.
 66 }
 67 
 68 
 69 - (void)applicationWillTerminate:(UIApplication *)application {
 70     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
 71     // Saves changes in the application's managed object context before the application terminates.
 72     [self saveContext];
 73 }
 74 
 75 
 76 #pragma mark - Core Data stack
 77 
 78 @synthesize persistentContainer = _persistentContainer;
 79 
 80 - (NSPersistentContainer *)persistentContainer {
 81     // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
 82     @synchronized (self) {
 83         if (_persistentContainer == nil) {
 84             _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"XIBAPP"];
 85             [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
 86                 if (error != nil) {
 87                     // Replace this implementation with code to handle the error appropriately.
 88                     // 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.
 89                     
 90                     /*
 91                      Typical reasons for an error here include:
 92                      * The parent directory does not exist, cannot be created, or disallows writing.
 93                      * The persistent store is not accessible, due to permissions or data protection when the device is locked.
 94                      * The device is out of space.
 95                      * The store could not be migrated to the current model version.
 96                      Check the error message to determine what the actual problem was.
 97                     */
 98                     NSLog(@"Unresolved error %@, %@", error, error.userInfo);
 99                     abort();
100                 }
101             }];
102         }
103     }
104     
105     return _persistentContainer;
106 }
107 
108 #pragma mark - Core Data Saving support
109 
110 - (void)saveContext {
111     NSManagedObjectContext *context = self.persistentContainer.viewContext;
112     NSError *error = nil;
113     if ([context hasChanges] && ![context save:&error]) {
114         // Replace this implementation with code to handle the error appropriately.
115         // 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.
116         NSLog(@"Unresolved error %@, %@", error, error.userInfo);
117         abort();
118     }
119 }
120 
121 @end

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值