2012-03-23 11 views
0

私は提案されたリストを見て、私のジレンマに合ったものを見ませんでした。ストーリーボード:ストーリーボードに指定されたUINavigation Controllerのルートビューを変更する

私は最初のストーリーボードプロジェクトを書いています。私は4つのタブを管理するUITabBarControllerを持っています。各タブには、ルートとしてのUINavigationControllerと、それぞれのビューの数があります。

ナビゲーションスタックの1つは、実際には3つのView Controllerの「リング」です。私はカスタムセグを使用して、単純な置き換え(私は1つのビューを重ねる)とナビゲーションスタックの通常の "杭打ち"を置き換えます。

これはすばらしく機能します。ストーリーボードとカスタムセグは医者が注文したものです。

しかし、私は3つのビューのうちのどれを開始するか(ナビゲーションスタックのルートになる)をユーザーに選択したいと考えています。ストーリーボードは、自分のうちの1つをルートとして選択することを主張しているので、私はそうします。しかし、実行時に、ユーザーは初期ビューを別にすることが必要な場合があります。そのため、ナビゲーションスタックのビューを変えたいとします。

nibベースのアプリでは、単にペン先から新しいコントローラをインスタンス化し、現在のルートをそのコントローラに置き換えます。

コントローラを取り出してストーリーボードで行うにはどうすればよいですか?

+0

OK。私はそれを持っていると思う。ちょっと回り道ですが、UIStoryboard :: instantiateViewControllerWithIdentifierメソッドが必要です。私はちょうどその場所に適切なストーリーボードを取得する必要があります。私はそれが私の満足に働いているときにコードを投稿します。 –

答えて

0

更新:コメントin another threadのおかげで、これを少し簡略化することができました。

OK。私はそれを考え出した。

ルートを置き換えるのではなく、適切なコントローラをオンにするだけです。これは、ルートを変更するにはコントローラーを再インスタンス化する必要があり、キツネは追いかける価値がないからです。これはUXには全く影響がないので、次のようにします。

/**************************************************************//** 
\brief Selects the initial search screen, depending on the user's choice. 
*****************************************************************/ 
- (void)selectInitialSearchAndForce:(BOOL)force   ///< If YES, then the screen will be set to the default, even if we were already set to one. 
{ 
    UITabBarController *tabController = (UITabBarController *)self.window.rootViewController; 

    [tabController setSelectedIndex:0]; // Set the tab bar to the search screens. 

    if (force) 
     { 
     UIStoryboard *st = [tabController storyboard]; 

     [[searchNavController navigationController] popToRootViewControllerAnimated:NO]; 

     UIViewController *newSearch = nil; 

     switch ([[BMLT_Prefs getBMLT_Prefs] searchTypePref]) 
      { 
      case _PREFER_MAP_SEARCH: 
      if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad) // The map and simple searches are combined, on the iPad. 
       { 
       newSearch = [st instantiateViewControllerWithIdentifier:@"map-search"]; 
       } 
      break; 

      case _PREFER_ADVANCED_SEARCH: 
      newSearch = [st instantiateViewControllerWithIdentifier:@"advanced-search"]; 
      break; 
      } 

     if (newSearch) // We push the controller, as opposed to changing the root, because it's easier, and doesn't violate any of our ground rules. 
      { 
      [[searchNavController navigationController] pushViewController:newSearch animated:NO]; 
      // In the case of the iPad, we use a standard navbar push, so we need to prime the simple view to properly populate the Advanced view back button. 
      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 
       { 
       UIViewController *simpleViewController = [[[searchNavController navigationController] viewControllers] objectAtIndex:0]; 

       simpleViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString([[simpleViewController navigationItem] title], nil) 
                             style:UIBarButtonItemStyleBordered 
                             target:nil 
                             action:nil]; 
       } 
      } 
     } 
} 
関連する問題