This is the correct way to detect this.
- (void)willMoveToParentViewController:(UIViewController *)parent{
if (parent == nil){
//do stuff
}
}
this method is called when view is pushed as well. So checking parent==nil is for popping view controller from stack