Well, your approach doesn't seem to be the most fortunate one to me.
What you could do is to replace the UITabBarController
with a UINavigationController
and go with the following approach:
- present your CustomViewControllerLogin modally. You can use something like this:
[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogin animated:YES];
set the rootViewController in the navigationController to be your CustomViewController1
in your CustomViewControllerLogin, once the login is done successfully, dismiss the CustomViewControllerLogin using the following:
[self dismissModalViewControllerAnimated:YES]
when this gets executed, your CustomViewController1 will be displayed. Do your app logic here and have a "Logout" button. You could put it on the navigation bar, on the right side for example.
when the user taps on this logout button, you do the same as you did for the login:
[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogout animated:YES];
I have seen a lot of apps where the UITabBarController is abused for purposes that it wasn't intended for. See for example this article.