I have an app that is based on a tab bar view with a welcome screen (that leads to either signin or sign up process). basically, if you are logged in – you go straight to the tabbar view and if not, you go to the welcome screen, where you can chose to either go to sign in or sign up. assuming that you go to either sign in or sign up, i would like the tab bar view to reappear, however, all the declarations are in the AppDelegate. how can I “go back” and call the tabbatcontroller? is the structure / flow of my classes correct at all?
so to repeat:
- user signed in -> first view is tab bar view
- user logged out -> welcome screen view –> sign in / up screen view –> tab bar view
what i am looking for is what do i need to write in this action method that is called once the user clicks on “sign in” in the sign in page:
-(IBAction)done:(id)sender {
?????
}
for reference, my appDelegate is:
if(user signed in)
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstTab alloc] initWithNibName:@"FirstTab" bundle:NSBundle.mainBundle];
UIViewController *viewController2 = [[SecondTab alloc] initWithNibName:@"SecondTab" bundle:NSBundle.mainBundle];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, secondNavController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
else
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SigninTabBarTemplateViewController *landingPage = [[SigninTabBarTemplateViewController alloc] initWithNibName:@"SigninTabBarTemplateViewController" bundle:nil];
self.window.rootViewController = (UIViewController *) landingPage;
[self.window makeKeyAndVisible];
}
There are many options you can consider.
This can be easily achieved with the use of delegate. If you want to close the VC that you presented modally, give it a
delegateproperty. The delegate will be sent a message when required, letting it dismiss the VC. A good way to go with delegate is to write a custom procotol.For example :
Now, make the object you want conforms to that protocol, for example the app delegate.
The implementation looks like this :
Now give
signInVCa delegate property, which will be set before being presented modally, and send the delegate a message when the sign in process is completed.You can write any method you want, this example is simplist, and it is useful to give the delegate some informations. In this case for example you could pass a user name, or user id, or what ever you want.
Another simple option is using notifications. This option lets any object informed when something happen, as long as it register for it. Given the same objects as the previous example, the app delegate will register for the notification, while the sign in view controller will post it.
More informations about delegates and notifications in Communicating with Objects.