Different actions on switching View on UITabBarController programmatically instead of by user?

StackOverflow https://stackoverflow.com/questions/22948796

  •  30-06-2023
  •  | 
  •  

質問

I have an app with Tab Navigation consisting of 5 independent views (for 5 tabs). EXCEPT: in one case I want to programmatically switch from one view(tab) to another.

Switching works, but I also want to pass a parameter by switching programmatically, so the destination view will look differently, than it was activated by user pressing the tab?

Is there any decent way to achieve this (except defining global variable ;) ?

役に立ちましたか?

解決

I have hooks in my App Delegate to help with this. This is how I do it in my code (note that each tab has a UINavigationController inside it):

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 
                            }
                        }];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top