0

I am creating an app that uses a UITabController with 5 tabs for navigation. Right now my app loads the first tab as the initial view upon app loading.

I want to be able to change that so I have a view that doesn't use my UITabController as the initial view, and once they click the one button on it, it brings them to the First View and displays the TabController.

I thought I'd simply set up a new view, change that one to the initial view controller and have a segue from the button to the TabController, but when I tried that and the view I wanted to with the button loaded first, but when clicking button it said something about needing to set up a NavigationController? Not sure what to do from here.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2122206
  • 51
  • 1
  • 1
  • 8

1 Answers1

1

I think it's best to leave your tab bar controller as the window's root view controller. You can present the initial view controller from the viewDidAppear method of the controller in the first tab, using presentViewController:animated:completion:. Do this with the animated parameter set to NO, and the initial view will be the first thing the user sees. When you're done with that view, just dismiss it, and you'll be back to the first tab's view.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Tried this didn't seem to work. Put this in the viewDidLoad on the first tab's .m file. UIViewController *masterView = [[MainViewController alloc] init]; [self presentViewController:masterView animated:NO completion:nil]; No error, but I get something in console saying: arning: Attempt to present on whose view is not in the window hierarchy! Also a warning that says Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via instantiateViewController – user2122206 Aug 29 '13 at 14:49
  • @user2122206, The first error is because you put the code in viewDidLoad instead of viewDidAppear as I said in my answer. The second error is because you created a scene in your storyboard and didn't give the controller an identifier. If masterView is that controller in the storyboard, then you need to instantiate it with MainViewController *masterView = [self.storyboard instantiateViewControllerWithIdentifier:@"your identifier here"]; not with alloc init. – rdelmar Aug 29 '13 at 14:57
  • I forgot to ask, now that I have this view controller on top when loaded, how would I dismiss it? I pretty much want it so when a button is clicked on the page it goes back to my view with tab controller. Thanks in advance! – user2122206 Aug 29 '13 at 15:17
  • @user2122206, in that button method just do [self dismissViewControllerAnimated:YES completion:nil]; – rdelmar Aug 29 '13 at 15:25
  • Ok great that worked out, only issue now is once it goes to that view it brings back up the LoginView controller again as soon as it's dismissed, assuming its because I added it to the viewDidAppear, so once it appears it brings back up that login view? How would I fix this? – user2122206 Aug 29 '13 at 15:40
  • @user2122206, you need to to put in an if statement and a static variable so that code will only run once. So in viewDidAppear put this: static BOOL first = YES; if(first) { first = NO; then do the presentation stuff – rdelmar Aug 29 '13 at 15:45
  • Only thing I noticed and haven't figured out yet when I cleaned and rebuilt was that it flashes for a breif second of the Second view before displaying the MainView, then once clicked it works like a charm there on out. ANy idea why it flashes the view with tabcontroller for a brief second before showing the login view? – user2122206 Aug 30 '13 at 00:44
  • No, I haven't noticed that. – rdelmar Aug 30 '13 at 00:57