How to check whether the ViewController is popped or pushed without using the BOOL variable ? Is there any inbuilt method that tells the whether it si popped or pushed ??
Asked
Active
Viewed 2,841 times
-5
-
2Could you try explaining a little more the issue? What are you trying to do exactly? Are you talking about UIVIewControllers being push and popped inside an UINavigationController? – Alexis C. May 15 '13 at 10:26
-
I want to set animation for the navigation controller and for that i need to check whether the view is popped or pushed when it is displayed ... so that based on that i can add different kind of animation.... – Parvez Belim May 15 '13 at 12:13
-
@ParvezBelim whats wrong with my answer and why down vote ? – Buntylm May 15 '13 at 13:35
3 Answers
2
if (self.navigationController != nil) {
// You can POP
}
or get All views.
NSArray* views = [myNavigationController viewControllers];
[views objectAtIndex:0] //will be the Root
And Can check current is Root or not like
if(self == [views objectAtIndex:0])
//Yes it is Root

Buntylm
- 7,345
- 1
- 31
- 51
2
for the following, please note: you need to have the same instance of the toCheckController
to get the correct result
NSArray* views = [myNavigationController viewControllers];
[views containsObject: toCheckController];//will return you yes/no
This will tell you if it is already pushed or not. If this returns NO, you cannot tell whether the view was popped or never pushed.

Nikita P
- 4,226
- 5
- 31
- 55
0
The UIViewController
has a property called isMovingToParentViewController
. You can call this in your viewDidAppear
or viewWillAppear
methods. If the vc is pushed it's true
, if it's popped it's false
.
Here is a similar answer: iOS how to detect programmatically when top view controller is popped?
Edit: (Only available in iOS 5 and up)
-
yes it works in few cases but not in all cases ... i tried the alternative one also that is - (BOOL)isBeingPresented NS_AVAILABLE_IOS(5_0); - (BOOL)isBeingDismissed NS_AVAILABLE_IOS(5_0); but this are also not working ... because to use this we have to place this function in view will disappear ... and i placed the animation code in view will apear method of another view control ... so after disappear is called another view's viewWillApear() is called...So not working in my case...but this is correct solution..I finally used BOOL to sort out the issue ...Thanx Tobi – Parvez Belim May 16 '13 at 12:25