Reputation: 8944
I have view controller say A i am going from A to B.Then on B by pressing back button i am coming to A.Now i want to know from which view controller i am coming back.Please tell me how can i do this.I know i can do it by using viewWillAppear
method but don't want to use this.
Please tell which is the best way of doing it?
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"view will appear called");
}
Upvotes: 1
Views: 1427
Reputation: 8944
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
NSLog(@"from VC class %@", [fromVC class]);
if ([fromVC isKindOfClass:[ControllerYouJustPopped class]])
{
NSLog(@"Returning from popped controller");
}
return nil;
}
This really saved me .
Upvotes: 1
Reputation: 59
You could use a navigation controller delegate and implement the following UINavigationControllerDelegate method:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UIViewController *fromViewController = [navigationController.transitionCoordinator viewControllerForKey:UITransitionContextFromViewControllerKey];
NSLog(@"%@", fromViewController.title);
}
Upvotes: -1
Reputation: 33
you can pass id of controller before pop
A.h
@property NSInteger childVC;
A.m
-(void)viewWillAppear:(BOOL)animated
{
if (_childVC == 3){
//todo
}
}
B.m
-(void) viewWillDisappear:(BOOL)animated {
A *parent = (A *)self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2];
parent.childVC = 3;
[super viewWillDisappear:animated];
}
I do not see other ways
Upvotes: 0
Reputation:
You have been push to B-VC from A-VC right.You can come back by popping.
self.navigationController!.popViewControllerAnimated(true)--Write this code in B-VC
VC-ViewController.
Upvotes: 1