2014-02-13 23 views
0

我不知道如何實現表視圖控制器的詳細視圖,當該表視圖控制器由於用戶與標籤欄控制器交互而出現時這不是應用程序的主要觀點。我想我需要創建第二個UINavigationController,但我不知道如何將它集成到使用它的主人和細節視圖控制器,雖然我有一個導航控制器,對我的主視圖控制器(EdgewoodSecretsMasterViewController)如何當多個tableViewControllers(無故事板)時pushViewController

作品(我讀PushViewController with tabBarController not working

我不是使用故事板。

我的應用的根視圖是一個稱爲EdgewoodSecretsMasterViewController的表視圖控制器用戶可以在它填充的表中選擇一行,顯示詳細視圖並返回到EdgewoodSecretsMasterViewController表視圖。

我在這個主視圖的底部也有一個標籤欄。它有3個選擇。一個是EdgewoodSecretsMasterViewController當用戶啓動應用程序時出現。用戶可以在表格中選擇一行,查看有關該選項的詳細視圖的信息並返回到表格視圖。

在應用程序委託我創建vcMaster,一個EdgewoodSecrets類

EdgewoodSecretsMasterViewController *masterViewController = [[EdgewoodSecretsMasterViewController alloc] initWithNibName:@"EdgewoodSecretsMasterViewController" bundle:nil]; 

UINavigationController * vcMaster = [[UINavigationController alloc] initWithRootViewController:masterViewController]; 

第二個標籤欄的選擇是一個信息視圖的作者信息頁面。用戶可以選擇它,並返回到原來的表視圖,但點擊第一個標籤欄選擇

WhoIsAuthor* vcAu = [[WhoIsAuthor alloc] init]; 

這兩種選擇工作,我希望他們。但不是第三個標籤。 第三個標籤是vcImportant

ImportantMasterViewController* vcImportant = [[ImportantMasterViewController alloc] init]; 

    initWithNibName:@"ImportantMasterViewController" 
    bundle:nil ]; 

在這裏,我把所有的選項卡中選擇到標籤欄控制器

UITabBarController *tabBar = [[UITabBarController alloc] init]; 

    NSArray* controllers = [NSArray arrayWithObjects:vcMaster, vcAu,vcImportant, 
         nil]; 

    tabBar.viewControllers = controllers; 
    [[self window] setRootViewController:tabBar]; 

第三個選項卡選擇帶來了另一個表視圖 - ImportantMasterViewController。該表視圖中填充了多個選項,但是當用戶做出選擇時,pushViewController指令不知道有關原始導航欄控制器的任何內容。在推送點self.navigationController沒有值。我認爲這是因爲標籤欄控制器是根視圖控制器。所以我認爲這是我不知道這麼說的最高級別/負責人。

PushViewController with tabBarController not working

我看到阿洛克·辛格回答說:「對於每一個你需要創建一個單獨的導航器選項卡」

我可以在我的appDelegate創建第二個UINavigationController對象。但我不知道如何使用它超越這樣

UINavigationController * ncImportant = [[UINavigationController alloc]  
     initWithRootViewController:importantMasterViewController]; 

設置它在應用程序委託好像什麼地方必須有一個堆棧,即認爲得到了推最後一個對象。看起來我應該把所有的視圖控制器都放在那個堆棧上。

在EdgewoodSecretsMasterViewController我推我喜歡這個

[self.navigationController pushViewController:self.detailViewController animated:YES]; 

詳細視圖詳細視圖出現,用戶可以來回走

在WhoIsAuthor我不彈出一個詳細的下屬視圖

In ImportantMasterViewController 我試圖推我的詳細視圖像這樣

[self.navigationController pushViewController:self.importantDetailViewcontrollers animated:YES]; 

詳細視圖不會出現。 我知道執行到此爲止。 我還可以看到,
self.navigationController 不具有價值像它在EdgewoodSecretsMasterViewController沒有在這一點上

那就是 - 如果我理解其他張貼正確的 - 因爲它需要它自己的導航控制器。但我不知道如何將應用程序代理中創建的導航控制器(ncImportant)與此推送聯繫起來

我不知道該如何思考,還是要閱讀並理解它。

謝謝 桂冠

+0

看看我的答案與示例屏幕。如果你需要一些代碼,請通過電子郵件聯繫。謝謝 –

回答

2

你需要把所有的選項卡中選擇到標籤欄控制器ncImportantvcImportant

UITabBarController *tabBar = [[UITabBarController alloc] init]; 

NSArray* controllers = [NSArray arrayWithObjects:vcMaster, vcAu,ncImportant, 
         nil]; 

tabBar.viewControllers = controllers; 
[[self window] setRootViewController:tabBar]; 
+0

謝謝!我現在只是經常發生一些常見的錯誤。我從來沒有想過我會很高興有我的代碼炸彈。但現在它正在超越這一點。 – LaurelS

+0

稍後...它不會顯示視圖,但重要詳細視圖控制器中的導航控制器具有值。我認爲這是進步。 – LaurelS

1
  1. UITabBarController爲您RootViewController的。

  2. 添加的所有選項卡,在每個選項卡,你可以用它初始化或者

    一)UINagivationController這又被初始化了 UIViewController實例。 b)或者只是您的UIViewContollers

  3. 在您的應用程序加載時,您始終可以選擇應顯示的特定選項卡。

  4. 然後,您可以使用Push或Modal方法來顯示OtherViewContollers1作爲TabBarController項目之一中所選項目的詳細信息。

看到這個:

  • 這是我的根視圖控制器(在其標籤欄有三個選項卡)

enter image description here

  • 這是一個DetailViewController其它有一個UITableView作爲實例。當我單擊上表View中的項目時,它會在TabBar上模態呈現。enter image description here

  • 看看它是如何呈現模態。

    enter image description here

希望幫助。

+0

以上所有代碼都使用CustomViews,而不是storyBoards。 如果您需要一些代碼示例,請通過[email protected]與我聯繫,並嘗試不使用此評論Stackoverflow的部分作爲聊天窗口。 :-) –