0

So recently I had to reorganize my tab bar and remove one the tabs for a view controller that I still need to access at the end of the app. I am using NSNotifications which triggers a method in the app delegate which basically switches the tab [self.myTabBar setSelectedIndex:REC_TAB];

Worked like a charm. Now that I can no longer select the tab, I'm finding I'm having trouble pushing/popping/presenting a view controller from the app delegate.

I'm new to this so any help would be appreciated.

Miles
  • 553
  • 1
  • 6
  • 8

1 Answers1

3

There's no reason that you have to do it from the app delegate -- you can if you want to, but there's no need. From any view controller, you can access the window's root view controller with self.view.window.rootViewController, and change it to whatever you want. Another way is to just present a modal view controller with presentViewController:animated: from any view controller.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I need to push it from the app delegate because within the method that's supposed to push the view controller, I call another method located in the app delegate. I've tried just about everything I can think of... `[self.view.window.rootcontroller push/present modal/viewcontroller]` and to no avail. I've also tried pushing from the tab bar as well as the navigation bar, but no dice. Any ideas? Maybe more specific? Either way, I appreciate your response. – Miles Dec 29 '12 at 23:57
  • @Miles, I need to know the structure of your app to answer your question. Is this view controller embedded in a navigation controller? If not, then you can't push it, but you should be able to present it. What is the root view controller of the window? Your tab bar controller? – rdelmar Dec 30 '12 at 03:35
  • It is embedded in a nav controller, and yes my tabBarController is the root. – Miles Dec 30 '12 at 22:26
  • It turns out it was easier to just push from another view controller. I had to do a bit of rearranging, but it all worked out. Thanks for the help! – Miles Dec 30 '12 at 22:55