This question might seem a bit silly but I've been searching for some time now for an answer but I couldn't find one. So I'm developing an app that integrates Parse push notifications between clients. The app has a UITabBarController
(TabBarViewController
as the custom class) in the storyboard
and at some point in the app (upon receiving a push while the app is closed) I have to set the TabBarViewController
as my RootViewController
for further action such as [TabBarController doSomething];
In summary, I am trying to display the 3rd tab (index:2) of my TabBarViewController
and executing a function found in the TabBarViewController
class to display stuff in the view of the 3rd tab.
I am trying to do the following:
In my AppDelegate.m in the didFinishLaunchingWithOptions: method:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
TabBarViewController* tabBarController = (TabBarViewController*)[storyboard instantiateViewControllerWithIdentifier:@"<StoryboardIDofTabBarViewController>"];
tabBarController.selectedIndex = 2;
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
[tabBarController doSomething];
I have a feeling the solution requires delegation but I don't really know how to implement it. My controllers are not embedded in navigation controllers so I'm not sure if I can push the TabBarController
.
Any help would be appreciated. Thank you
This works perfect for me in application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
AppDelegate.h
AppDelegate.m
** Verify that the "instantiateViewControllerWithIdentifier" matches the storyBoard ID in the storyboard. Hope this helps.
Screenshot of storyboard: