iOS開發從入門到精通--XIB使用介紹

來源:互聯網
上載者:User

標籤:

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使用介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.