2013-02-06 28 views
1

以下看起來像是一個典型的用例:您使用顯示登錄屏幕的LoginViewController啓動應用程序。一旦用戶成功登錄後,您想要顯示您的應用程序的主視圖(我們稱之爲MainViewController)。如何在不使用UINavigationController的情況下在新的非模型視圖控制器中轉換?

您不希望將LoginViewController放到UINavigationController中,隨後將MainViewController放到它上面,因爲沒有理由將LoginViewController保留在堆棧底部,因爲它不會再顯示。此外,在應用程序的後續啓動中,您將確定您已獲得某種類型的登錄令牌,並且永遠不會顯示LoginViewController,因此從啓動到啓動導航控制器的堆棧會有不一致。

出於同樣的原因,您也不希望從LoginViewController模態地呈現MainViewController(如果它是模式,它會保持LoginViewController加載)。

您也不希望將窗口的rootViewController設置爲MainViewController(它之前已設置爲LoginViewController),因爲這不會允許您進行轉換。

我想就上述邏輯是否有缺陷提供一些反饋,實際上其中一種情況是正確的嗎?或者,如果不是,其他人爲這種情況做了什麼?

回答

4

爲什麼不使MainViewController成爲您的應用程序的根視圖控制器,並在啓動時以模態方式呈現LoginViewController(如果您沒有登錄令牌)?

+0

嗯好吧,這不是一個壞主意。然而,我必須確保MainViewController可以在沒有有效的登錄會話的情況下創建,但我猜是因爲它的視圖最初不會顯示(它會立即堆疊)它是viewDidLoad,不會調用類似的函數然而。 – Marplesoft

+0

一個跟進,雖然...如果LoginViewController是在導航堆棧的頂部,當我彈出它時,視圖將向右滑動以顯示MainViewController的視圖,哪些iOS用戶已經聯想到移回不前移。隨着前進,他們可能會認爲從登錄移動到主要。思考? – Marplesoft

+1

我也是這樣做過的。當你關閉LoginViewController時,你有多種關於如何解除它的選項,它不僅僅是一個向右的幻燈片。請參閱http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html和modalTransitionStyle – bandejapaisa

2

我有這種應用中,我已經通過去除LoginViewController這是當前對象和並與HomeViewController上聚焦添加TabBarController這樣

/* remove the current Login screen and show the 2nd tab */ 
    NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; 
    [newArray removeObject:self]; 
    [self.tabBarController setViewControllers:newArray animated:YES]; 

當使用從應用程序退出,然後實現我創建登錄屏幕並添加到堆棧,否則直接從應用程序註銷時直接進入HomeViewController

,然後我將LoginViewController重新添加到堆棧中,並將UITabBarController的當前索引分配給LoginViewController,如下所示

NSMutableArray *array =[NSMutableArray arrayWithObject:loginController]; 
     NSMutableArray* oldArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; 
     [array addObjectsFromArray:oldArray]; 

     [self.tabBarController setViewControllers:array animated:YES]; 
     [self.tabBarController setSelectedIndex:0]; 

     self.tabBarController.tabBar.hidden=YES; 
+0

我不知道我關注 - 是你的LoginViewController裏面的TabBarController?另外,你能用這種方法在屏幕之間轉換嗎? – Marplesoft

+0

是的logincontroller是tabBarController的一部分,我已經在多個應用程序沒有問題,通過使用數組可以刪除loginController和註銷後只是在第一個索引添加它,這不是很難的東西,我必須說 – nsgulliver

+0

好吧,但如何你指定過渡嗎? – Marplesoft

相關問題