2011-11-19 61 views
1

我正在學習新的iOS 5.0上的Storyboard。它似乎很簡單的使用和實現,但我的問題是... 我怎樣才能更新舊的Xib到故事板?Xib Vs Storyboard,如何更新

例如,當沒有故事板時,我開發了一些課程,並且這些課程中的某些課程附帶了幫助我快速設置自定義佈局的xib文件。 很顯然,當我使用這種類時,我需要使用initWithNibName:bundle來實例化它,現在它已經可以使用了,我可以多次使用它,因爲佈局是在xib內編碼的。

Now Storyboard ... Storyboard不允許從xib加載視圖控制器,我沒有找到一種方法來加載故事板文件在主故事板內。似乎我需要重新配置一個特定的視圖控制器的佈局,每次我在一個新的項目中使用它。 看來,現在我不得不重新配置我的控制器在每個使用此控制器的新應用程序中的佈局,而不是使用內部佈局的xib文件。

也許有一些我不明白。 任何人都可以幫助我理解使用故事板的最佳方式?

預先感謝您。

Gabriele。

編輯在回答sw3n

也許我理解的感謝sw3n。下面的代碼工作,但這是完全正確的?

// All this code is implemented inside the MyViewController class. 

// Attached to an UIButton; 
- (void)loadNewController:(id)sender { 
    [self performSegueWithIdentifier:@"newControllerIdentifier" sender:sender]; 
} 

- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender { 
    // As suggested by sw3n 
    // Load the storyboard from file. 
    UIStoryboard *storyboardTest = [UIStoryboard storyboardWithName:@"StoryBoardLoad_Test" bundle:nil]; 
    // Instantiate the viewController that live in the storyboard file 
    UIViewController *destinationViewController = [storyboardTest instantiateViewControllerWithIdentifier:@"newControllerIdentifier"]; 

    // Instantiate a segue to start the chain 
    UIStoryboardSegue *segue = [[UIStoryboardSegue alloc] initWithIdentifier:identifier source:self destination:destinationViewController]; 
    [self prepareForSegue:segue sender:sender]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"newControllerIdentifier"]) { 
     [segue.destinationViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 

     // Are there new options to present the controller? 
     // If I was in a NavigationController a could obviously push it. 
     [self presentModalViewController:segue.destinationViewController animated:YES]; 
    } 
} 

回答

3

這是你在找什麼?

(UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil 
0

界面生成器:

  1. 在您的視圖控制器選擇SEGUE
  2. 轉到屬性選項卡
  3. 給SEGUE名稱
  4. 設置過渡方式

代碼:

[self performSegueWithIdentifier:@"mySegueNameFromInterfaceBuilder" sender:self]; 
+0

這不會回答我的問題。這是storyboard在單個.storyboard文件中的工作方式。我有興趣使用多個故事板文件。 – Gabriele

2

聽起來有點遲,但似乎沒有結論的答案。你可以使用上面提到的Nightfirecat的storyboardWithName()。從UIStoryboard創建新的ViewController,並將新的ViewController掛接到視圖層次結構中所需的位置。您可以使用多個故事板文件以這種方式分割您的用戶體驗設計。我寫了一些關於如何在我的網站上將其作爲rootcontroller掛鉤的內容,但它應該在任何地方工作。