码迷,mamicode.com
首页 > 其他好文 > 详细

XIB使用

时间:2017-09-29 21:08:02      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:gen   resources   actual   problem   started   case   graph   ted   obj   

  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

 

XIB使用

标签:gen   resources   actual   problem   started   case   graph   ted   obj   

原文地址:http://www.cnblogs.com/vector11248/p/7612367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!