0

I want to get a viewcontroller from storyboard, this viewcontroller has already been exist, so using[MyStoryboard instantiateViewControllerWithIdentifier:@"identifier"];is absolutely not correct.Any suggestion would be a great help for me, thanks very much!

Paulw11
  • 108,386
  • 14
  • 159
  • 186
John
  • 525
  • 3
  • 14
  • you need to traverse through array of your view controllers, have you created a navigation hierarchy? – rishi Jul 14 '14 at 04:23
  • Depending on when you instantiate your view in that matter it won't work. as http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy states, it won't work in the viewDidLoad method, however if you put it either in viewDidAppear, or in another method on demand it will work. I just verified that I can call a VC using a button on demand on the latest iOS 7 SDK using that call. – dmason82 Jul 14 '14 at 04:54
  • Actually it's a tabbarController, and I want it in APPDelegate – John Jul 14 '14 at 05:07

1 Answers1

1

You have access to all the tab bar controller's content controllers through its viewControllers property, and you can get the tab bar controller with self.window.rootViewController in the app delegate.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • the key is I got a login viewcontroller, which is the rootViewController, and this login viewcontroller makes a modal segue to tabbarController, so I cannot get the tabbarController using self.window.rootViewController – John Jul 14 '14 at 06:09
  • @user3779315, I don't think that's the best structure for you app. The tab bar controller really should be the root view controller. You can present the login controller from the viewDidAppear method of the controller in the first tab (with no animation), and it will be the first thing the user sees. When you're done with log in, you dismiss it, and you'll be back to that first tab controller. This way, you don't have the login controller present for the life of the run, when you only need it for a brief time at the beginning. – rdelmar Jul 14 '14 at 15:35
  • Thank you for the response and fantastic answer! I'm gonna change the structure – John Jul 15 '14 at 05:09