1
votes

I have a Tab Bar application that shows several tabs. I case of notification I want user to be directed to a view controller with the ability to push "Back". When my app was only Navigation controller app, I used this code in my AppDelegate:

UIStoryboard *mainStoryboard = self.window.rootViewController.storyboard;
DetailViewController *detailViewController = (DetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"detailViewController"];
[(UINavigationController*)self.window.rootViewController pushViewController:detailViewController animated:NO];

This code used to work fine until I converted my app to be Tab Bar. Seems like the "self.window.rootViewController" is not longer of type "UINavigationController" and therefore calling "pushViewController" generates an exception saying method doesn't exist. Any way to make this work on a Tab Bar application?

Thanks

1
Do you want this new viewcontroller to cover over the tab bar? What do you want the back button to do?Joel
Yes. It is a news app. If user swipes the notification I would like to open a view controller showing the news item directly. Then by pressing back I want him to return to the regular tab view.bashan

1 Answers

2
votes

You should present your notification controller as modal (presentViewController:animated:completion:), and inside that controller you provide a way to close it, probably a button on top bar.

EDIT: Thanks for Dimitry's answer I was able to go on the right track. I just had to make a small trick in order to preserve the top navigation bar and the bottom tool bar. I did it by using a "UINavigationController" instance. Here is the code:

UIStoryboard *mainStoryboard = self.window.rootViewController.storyboard;
DetailViewController *detailViewController = (DetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"detailViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
navigationController.navigationBar.tintColor = [UIColor blackColor];
navigationController.toolbar.tintColor = [UIColor blackColor];
[self.window.rootViewController presentViewController:navigationController animated:YES completion:NULL];