iOS开发从入门到精通--XIB使用介绍

XIB使用介绍:
首先我们删除一些不需要的东西:
iOS开发从入门到精通--XIB使用介绍_第1张图片

然后我们创建一个新的视图控制器
iOS开发从入门到精通--XIB使用介绍_第2张图片

红色箭头Also create XIB file要勾选上
iOS开发从入门到精通--XIB使用介绍_第3张图片

这个时候,我们可以看到有三个文件创建成功了,其中有一个RootController.xib文件,在这个里面就看到了一个像手机一样的视图,我们可以在右边进行拖拽一些控件在上面

下面启动这个视图代码要在代理AppDelegate.m书写:
要引入#import “RootController.h”

#import "AppDelegate.h"
#import "RootController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //创建一个窗口对象
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    //方法一:显式加载xib文件
    //创建根视图控制器对象
    //参数一:创建时加载xib资源文件名,加载xib作为视图控制器视图
    //参数二:是指主文件包,xib所在的位置,mainBundle是主资源文件包。如果传nil,函数会自动到mainBundle中查找

//    RootController * root = [[RootController alloc]initWithNibName:@"RootController" bundle:[NSBundle mainBundle]];

    //RootController * root = [[RootController alloc]initWithNibName:@"RootController" bundle:nil];

    //方法二:隐式加载xib文件
    //如果系统中有xib的名字(RootController.xib)和类名字相同(RootController),
    //init函数会自动去加载RootController.xib文件
    RootController * root  = [[RootController alloc]init];

    self.window.rootViewController=root;

    [self.window makeKeyAndVisible];

    return YES;
}

- (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:.
}

@end

你可能感兴趣的:(ios开发,ios开发从入门到精通)