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

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

  •  30-06-2023
  •  | 
  •  

Question

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 ;) ?

Était-ce utile?

La solution

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 
                            }
                        }];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top