I am using UINavigationController to deal with controllers navigation
In Normal Case
RegistrationView -> LoginView -> HomeView
From HomeView & any other next controllers there is one screen called Setting is opened up which is having Logout Button. On the click of this button screen will be popped to the LoginView in normal case.
- (IBAction)btnLogoutSelected:(id)sender
{
NSArray *navArr=self.navigationController.viewControllers;
for (UIViewController *nav in navArr)
{
if ([nav isKindOfClass:[LoginViewController class]])
{
[self.navigationController popToViewController:nav animated:YES];
}
}
}
Once User will be registered & If user Logged in once, here application is having autoLogin functionality. So at that time LoginView will not be in the Navigation count. So in this scenario above code is not working. So at that time I am not able to go to the LoginView. I need help to solve this issue. Thanks in advance
In case you don't have an instance of LoginViewController
on navigation stack, simply create it:
LoginViewController* loginController = [[LoginViewController alloc] init]; //use appropriate initWith... method
Then you can use viewControllers
property of UINavigationController. You can replace current view controller with loginController
, or insert loginController
at given index and pop to it.
NSMutableArray* newViewControllers = [self.navigationController.viewControllers mutableCopy];
[newViewControllers replaceObjectAtIndex:[newViewControllers indexOfObject:self] withObject:loginController];
[self.navigationController setViewControllers:newViewControllers animated:YES];
Try This
if ([self.navigationController.viewControllers containsObject:objLogin]) {
[self.navigationController popToViewController:objLogin animated:TRUE];
}
else {
[self.navigationController pushViewController:objLogin animated:TRUE];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With