0

我是ios的新手。我試着用UITabbarController工作,當我嘗試從ViewController(這個ViewController不是Tabbar中的一個項目)傳遞數據到Tabbar中的其他ViewController時,我遇到了一些問題。在這種情況下,當我點擊按鈕登錄按鈕時,會出現「歡迎購物」並且登錄表單中的用戶名將在「歡迎購物」中進入標籤。 you can see picture below for more details如何在使用presentViewController和UITabbarController時傳遞數據

我用下面的代碼,使「開山鼻祖店」控制器出現:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UITabBarController *tabbarController= [storyboard instantiateViewControllerWithIdentifier: @"tabbarID"]; 
    [self presentViewController: tabbarController animated: YES completion: nil]; 

所以任何想法對我來說,通過用戶名(在LoginController中)爲標籤(WelcomeToShopController)?

回答

1

我研究後,我的問題得到解決:)。因爲我使用tabbar和navigationController,所以我應該實例tabbar - > NavigationController - > ViewController。在我的情況下,下面的代碼將完美工作。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UITabBarController *tabbarController= [storyboard instantiateViewControllerWithIdentifier: @"tabbarID"]; 
    UINavigationController *nav = (UINavigationController *)[tabbarController.viewControllers firstObject]; 
    HistoryOrderingController *historyOderingVC = (HistoryOrderingController *)[[nav viewControllers] firstObject]; 
    historyOderingVC.user = self.user; 
    [self presentViewController: tabbarController animated: YES completion: nil]; 
相關問題