2016-02-06 20 views
0

我正在處理一個選項卡式應用程序。我的主頁上有一個按鈕,可以進入第二個選項卡頁面,但當它加載時,它將擺脫底部的選項卡。 如何防止這種情況發生?我的代碼:呈現新的視圖控制器。選項卡式圖標消失

func manageButtonPressed() { 
let NVC:SecondViewController = SecondViewController() 
self.presentViewController(NVC, animated: true, completion: nil) 
} 
+0

你對現有的視圖的頂部呈現一個視圖下,如果你不希望這樣做,那麼你應該做一個自定義視圖的標籤視圖或使用uinavigationclntroller和showViewController而不是 – bolnad

+0

你可以請給代碼做到這一點?我很快就很新。 – simon

回答

0

替換:

self.presentViewController(NVC, animated: true, completion: nil)

有了:

self.tabBarController?.selectedIndex = 1

這是假設你的主頁按鈕是在索引0上的第一個選項卡按鈕標籤欄,而第二個VC位於索引1的第二個選項卡上。您可以根據標籤欄的位置更改索引。

0

您希望使用showviewController方法關閉uinavigationcontroller。

因此,在您調用presentViewController的視圖的主要故事板中,您需要添加一個UINavigationController。然後你就可以在視圖中調用

self.navigationController.showViewController(NVC, sender: self) 

然後,它會添加視圖到導航堆棧的頂部,將標籤欄

相關問題