2014-04-08 26 views
0

我有一個包含5個獨立視圖(5個標籤)的Tab Navigation應用程序。 除了:在一種情況下,我想以編程方式從一個視圖(選項卡)切換到另一個。以編程方式而不是用戶切換在UITabBarController上切換的不同動作?

切換工作,但我也想通過以編程方式切換參數,所以目標視圖看起來會不同,而不是用戶按下該選項卡激活?

是否有任何體面的方式來實現這一點(除了定義全局變量;)?

+0

使用協議和代表,而不是全局變量 – Malloc

回答

0

我在我的App Delegate中有鉤子來幫助解決這個問題。這就是我要做的事在我的代碼(注意,每個標籤都有它裏面一個UINavigationController):

SLAppDelegate *delegate = (SLAppDelegate *)[[UIApplication sharedApplication] delegate]; 

UIView * fromView = delegate.tabController.selectedViewController.view; 
UIView * toView = [[delegate.tabController.viewControllers objectAtIndex:3] view]; 

[UIView transitionFromView:fromView 
          toView:toView 
          duration:0.5 
          options: UIViewAnimationOptionTransitionFlipFromRight 
         completion:^(BOOL finished) { 
          if (finished) { 
           delegate.tabController.selectedIndex = 3; 

           MapViewController *map = (MapViewController *)[delegate.navMapsController.viewControllers objectAtIndex:0]; // map view is the only VC in the navController 
           // do something with the map view 
          } 
         }]; 
+0

是的,基本上這就是我正在尋找:我不知道事件需要一個轉換,我只能訪問ViewController類,然後才能使其處於活動狀態。 –

+0

太好了。在這種情況下,您應該將其標記爲接受的答案。 –

相關問題