0

I am new to iOS development and I try to create an app that has a login view and after successful login it presents a tab bar menu with 3 items.

Menu item 1: is the default one that appears when the tab bar is loaded.

Menu item 2: is an application form. After successful application submission, it loads the default menu item using the code below.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Default_Menu"];
[self presentViewController:vc animated:YES completion:nil];

Menu item 3: is the logout and it is supposed to load the login screen with the following code:

[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popToRootViewControllerAnimated:YES];

The problem is (I guess) that after a successful form submission and the subsequent reloading of the default menu item, a new view hierarchy is created. The result is that after a successful form completion, selecting "Logout" leads to the view just before the form submission (text fields are appeared completed with user's input etc). A second "Logout" seems to lead to the login view but this is not the desired behaviour (one logout selection should be enough).

Are there any ideas on how I can stay on the desired view hierarchy and access the initial login view immediately?

user9839468
  • 31
  • 1
  • 5

1 Answers1

0

You don't have to instantiate your default tab view controller again, it's already loaded in the memory so simply just switch to it using this code:

self.tabBarController.selectedIndex = 0;

Now regarding the view hierarchy, you can simply make your storyboard with 4 view controllers:

  1. Login which is the default one (will automatically appear)
  2. Link it with a segue to a Tab bar controller
  3. Perform this segue when the login succeeds
  4. Add 3 child controllers in the storyboard which are your three tabs :)
  5. The first one appears by default

I hope this solves your problem

Boda
  • 1,484
  • 1
  • 14
  • 28
  • Actually, the submission is executed in several steps (multiple views) and thus `instantiateViewControllerWithIdentifier` was convenient in the sense that is reinitiated the tabBarController. – user9839468 Jan 28 '15 at 10:18
  • But UITabBarController is not intended to be used like this, maybe you should add manual UIButtons and do whatever you want with their actions :) – Boda Jan 28 '15 at 10:19
  • Actually, the submission is executed in several steps (multiple views) and thus `instantiateViewControllerWithIdentifier` was convenient in the sense that is reinitiated the tabBarController. So @Aubada the solution you proposed, when re-selecting Menu Item 2 it reloads the last used view of Menu 2 (not the initial view of Menu 2). Additionally, do you have any similar solution for the case of iPad device where I use SplitViewController instead of TabBarController? – user9839468 Jan 28 '15 at 10:23
  • Maybe you can use my solution and implement viewWillAppear in your tab view controller to reset the UI status – Boda Jan 28 '15 at 10:25