码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2016-07-31 00:21:40      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

XIB使用介绍:
首先我们删除一些不需要的东西:
技术分享

然后我们创建一个新的视图控制器
技术分享

红色箭头Also create XIB file要勾选上
技术分享

这个时候,我们可以看到有三个文件创建成功了,其中有一个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开发从入门到精通--XIB使用介绍

标签:

原文地址:http://blog.csdn.net/android_it/article/details/52076090

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