Wait for popToRootViewControllerAnimated: YES animation done
I have a menu based navigation system. The menu is a tableView. Every time the user clicks on one record in this table, I want to switch to a different view manager, and if there is any view, then I want to clear the navigation stack first.
This is what I do
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[(UINavigationController *)self.tabBar.selectedViewController popToRootViewControllerAnimated:YES];
self.tabBar.selectedIndex = indexPath.row;
}
But
self.tabBar.selectedIndex = indexPath.row;
Don't allow popToRoot animations. Is there a way to know when the animation is done?
thank
source to share
in your root controller, when rootViewController calls - (void)viewDidAppear:(BOOL)animated
, it means the animation is complete.
You can program the code rootViewControllers - (void)viewDidAppear:(BOOL)animated
If you want the code to be in the current ViewController, I think it has 2 ways:
1.add a delegate
in root controller when called - (void)viewDidAppear:(BOOL)animated
use delegate
to send message
2.add a notification in the root controller when you invoke a - (void)viewDidAppear:(BOOL)animated
notification message. And in the current ViewController you can get notification
source to share
The accepted response delegate or notification method works fine, but I find this method more convenient as it does not pass any logic to the root view controller, which is only the middle destination of the transition.
You can use Core Animation transaction. This way you have a completion block that the navigation controller doesn't offer.
I am picking up the variable tabbarcontroller in front of the block, because if we don't use tabbarcontroller in the block. It doesn't create any save loop because the block ends and disappears
[CATransaction begin];
UITabBarController *tabController = self.navigationController.tabBarController;
[CATransaction setCompletionBlock:^{
tabController.selectedIndex = 2;
}];
[self.navigationController popToRootViewControllerAnimated:YES];
[CATransaction commit];
The answer was copied from Joris Kluivers in the response block completion for popViewController and it works great for me
source to share
None of the answers worked for me, the only idea for me is to keep track of which controller and when it is presented.
Example:
https://github.com/dzenbot/iOSBlocks/blob/master/Source/UIKit/UINavigationController%2BBlock.m
Same technique provided in this answer: fooobar.com/questions/76380 / ...
only difference: github is category, answer is subclass
source to share