2013-04-09 18 views
1

我跟着一些教程中的應用程序啓動時創建一個開放的大門動畫,但它調用的更改「initWithNibName」到「storyboardWithName」

廈門國際銀行文件,我想打電話給故事板和我不有這個足夠的經驗。 這裏是我的代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    self.viewController = [[[OpenDoorsViewController alloc] initWithNibName:@"OpenDoorsViewController" bundle:nil] autorelease]; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

回答

5

如果你只是要加載的初始視圖控制器應用程序啓動時的故事板,只需在application:didFinishLaunchingWithOptions:中返回YES即可。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    return YES; 
} 

如果你想從故事板加載特定的控制器,則需要通過

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil]; 

先拿到storybard實例,然後用它來實例化你需要

UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"controllerIdentifier"]; 
控制器

其中controllerIdentifier已被分配爲故事板標識符到Interface Builder中的控制器。

下面是加載特定視圖控制器的示例,在啓動時將其呈現。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil]; 
    UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"controllerIdentifier"]; 
    self.window.rootViewController = controller; 
    return YES; 
} 
+0

工作就像一個魅力!謝謝 – 2013-04-09 18:16:36

1

如果你開始一個新的iOS項目,並選擇「使用故事板」,故事板將自動爲預裝你。

故事板是與您的應用程序的所有控制器(場景)的地方,並引用一個,你需要使用

UIViewController *controller = [[UIStoryboard storyboardWithName:@"storyboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"an identifier"]; 
+0

你能做到的 - (BOOL)申請:(UIApplication的*)應用程序didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions { – supermarin 2013-04-09 17:20:58