UINavBarController connecting the same UIViewController to multiple navigation controllers - objective-c

I have a storyboarded app with a chain of tableviews followed by a detail view. Kind of the classic iPhone app. There are 4 tabs and each one leads to a navigation controller.
The issue is I really want to avoid unnecessary glue code since the app is basically finished. If it was possible to connect the Search and Favorites (bottom two off the tab bar) controller as 'Root View Controllers' to the same UIViewController I would be done. However, this won't work since a view controller can only be the root view controller to one tab. So as you can see I've instituted two dummy UIViewControllers that forward you to the UIViewController in the middle. Now, unfortunately, I have to write code to make that central view controller a fake root view controller to disable the appearance of the back button, and prevent popping to the blank root when you double-tap the tab bar.
Has anyone got a more elegant solution?

This appears to be a flaw in Storyboards. One workaround would be to use simple view controllers for each navigation controller's rootViewController. Put a UIContainerView in each that points to the UIViewController you want to share.

Related

Embedding navigation controllers in a tabbarcontroller that is not the root view

I’m having some trouble with a integrating a navigation controller inside a tabbarcontroller that is not in the root view. My issue is that the root view, which leads to the tabbarcontroller is embedded in a navigation controller. Naturally, since the root view leads to the tabbarcontroller then each tab uses that root view’s navigation controller. Ideally I’d like to wrap each tab in its own navigation controller so that I could adjust them accordingly. I’ve tried using a modal segue and it allows me to put each tab in its own navigation controller, but this implementation does not work due to a sliding side menu plugin I am using. Embedding a navigationcontroller in each tab causes my autosizing to think there are two navbbars (because there are.) Any ideas? Is there a way I can maybe remove the navigationcontroller from latter views and keep it on the root?
TabBarControllers are meant to be root controllers, so your best course of action is likely going to be restructuring the navigation of your app to fit this paradigm. If you don't want the TabBarController to be the first view that the user sees (for instance, if your app has a login screen) then you can just modally present the login view controller over the top of the TabBarController when the app starts up (if needed).
Barring that, if you're just looking for a quick fix for your double navigation bar issue, you just want to get around your double navigation bar issue, you could just set the Top Bar property for your NavigationController to "none", as shown below.

Storyboard with NavigationController and TabController

It seems like this should be easy to figure out, but I haven't had any luck this afternoon. I threw together this quick, simplified storyboard mockup of my problem.
Basically, I would like the table view controllers below to also be in a tab bar controller (in addition to the already present navigation controller). The tabs would switch between the two table view controllers.
Right now, the view controller with the buttons acts as a sort of menu. Each button leads to one of the table view controllers. Ideally this view controller would not have the tab bar visible, and would only be reachable from back buttons on the nav bars of the table view controllers.
I've tried a few different ways of embedding into a tabbarcontrollers but none of them produce the desired result:
-I've tried selecting both table view controllers and embedding those in a tab view controller. The tabbar doesnt show up in simulator, and the 'unreachable scene' warning appears.
-I've tried embedding the initial nav controller into a tabbarcontroller. This creates a tab entry for the first 'menu' page. It also causes issues with push segues once I connect the tableviews to the tabview.
I would be fine implementing some programmatic options on top of the storyboard, I just chose storyboarding for this project since it's a relatively simple presentation of data.
What is the proper way of going about this? Thanks!
A tab bar controller needs to be the root view controller of your view hierarchy. It goes against the HIG and Apple's standards to put a tab bar controller inside of any other type of container controller.
From the Apple docs:
When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.
So, the bottom line here is you need to rethink your design. One option would be to set the UITabBarController as the root view of your window, and then have each of your UITableViewControllers inside of a UINavigationController, which is placed inside of the UITabBarController. In this way, you still get the navigation bar, and stay within Apple's design guidelines (you also won't get those pesky warnings, and Apple may even be throwing an exception nowadays if you try to install a UITabBarController as anything other than the root view of the window).
I accept JMStone answer but we might get into situation where we need to put tab bar controller inside other controller especially table view controller.
Please refer Storyboard navigation controller and tab bar controller
and also the good example by Matthjin: http://cl.ly/VQLa
Hopes it help some one who want to put tab bar controller inside table view controller and wants proper navigation.

UISearchBar on iPad table view disappearing below navigation controller bar

I'm working on a Universal app, using storyboards, and I've added a UISearchBar and a UISearchDisplayController to one of my table views. I've hooked it all up, and can search fine. The problem is when I push a new view controller onto the navigation stack. On the iPhone, this is fine, but on the iPad, it results in the pushed view controller being offset underneath the navigation bar (I had to manually make the navigation bar reappear so that you could get back).
Then, when you navigate back to the original table view where the search was taking place, the search is still active, but the UISearchBar is now hidden behind the navigation bar, meaning there is no way to dismiss it without deleting the query. It also means that it is not longer usable, since you can't get back in to it.
Probably best illustrated using some screenshots.
Here is how it looks when you first open the tableview:
Then doing the search is fine:
Clicking through to the next screen, we can see the issue:
And then back on the original screen, still doing the search but no search box:
Then, if I delete everything from the search box, and get rid of the overlay, I can see the search box when I scroll the table view up, but can never reach it. I can't get a reliable screen grab of that though.
I've looked everywhere for a solution but haven't been able to find one. I've tried calling [self setNeedsDisplay] and [self setNeedsLayout] in the viewDidAppear method, but that seems to have no effect. It seems to rectify itself if I change the orientation of the device, and I was trying to replicate what it would do in that situation by calling those methods.
The structure of the iPad storyboard is: SplitViewController -> Navigation Controller -> UITabBarController -> UITableViewController (contains UISearchBar etc.f) -> UITableViewController
I submitted this issue to Apple DTS, and they responded:
The structure of the iPad storyboard is: SplitViewController -> Navigation Controller -> UITabBarController -> UITableViewController (contains UISearchBar etc.f) -> UITableViewController
The fact is that your project architecture does not follow our guidelines which are:
From the Combined View Controller Interfaces section of the View Controller Catalog for iOS:
When combining view controllers, however, the order of containment is important; only certain arrangements are valid. The order of containment, from child to parent, is as follows:
Content view controllers, and container view controllers that have flexible bounds (such as the page view controller)
Navigation view controller
Tab bar controller
Split view controller
Basically, you should have a structure as follows:
SplitViewController -> UITabBarController ->Navigation Controller-> UITableViewController (contains UISearchBar etc.f) -> UITableViewController>

SIGABRT error when setting Tab Bar View Controller to custom view controller

I have been developing an iPhone application using the Detail View template. At some point I realized that I wanted my application to have a Tab Bar View controller as the root view controller. It seems that you do not want to push a tab bar view controller onto a navigation view controller. So I decided to start a new tab bar project and migrate my existing application code over. I thought this would be easiest.
So I have done that and the project builds without a problem. But I cannot seem to reassign the tab bar view controllers to ones which I already have. So I am replacing, "FirstViewController" with one of my custom ones. When I attempt to run the application it calls:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
And bombs with a SIGABRT error. I'm not sure why this is. I cannot see what the default view controller (firstviewcontroller) is implementing that my custom view controller is not.
Can anyone give me some ideas of what I should check?
Thanks!
update
It seems that my problem is related to the fact that my custom viewcontroller is of type UITableViewController. If I change this to be of type UIViewController it seems to work.
Update
I added a Navigation controller to the storyboard and created a relationship from it to a blank TableViewController. Then I assigned this TableViewController to my custom UITableViewController class. This seems to work. I'm not sure what plumbing was missing before.

iOS 5 storyboard, programmatically determine path

I'm having trouble to achieve the following using a storyboard:
When setup is not done:
run app -> show settings view controller -> show main navigation controller
When setup is done:
run app -> show main navigation controller
So basically, I want the app to programmatically start with the settings view in certain cases, and otherwise skip right ahead to the main navigation controller.
I did manage to show the settings view with a modal style segue from the main navigation controller, but I don't know how to display it before the main navigation controller is displayed. Any ideas?
By default, the initial view controller from your main storyboard is instantiated and displayed automatically when your app starts up. To prevent this happening you need to remove the UIMainStoryboardFile setting from your info.plist file.
With no default view controller, you are now free to create one programmatically at app startup. See the UIStoryboard documentation. Use +storyboardWithName:bundle: to load the storyboard and then use –instantiateViewControllerWithIdentifier: to create the correct view controller. You will also need to create a main UIWindow and add the view controller's view to it just like you used to do with .nib based UI. Note that without the UIMainStoryboardFile setting a main window is not created for you - read the explanation.
I managed to do it a bit different:
Use a UINavigationController as the initial view controller.
Create a root view controller that will manage the decision of what to load.
Create a Storyboard Segues from the root view controller to the main view and to settings view, and give the segues proper identifiers.
Call the performSegueWithIdentifier with the proper identifier from your root view controller.
Just another solution, hope this helps.
I did something similar to amoshaviv, his advice is sound. I did it slightly different though, and I'll give some more info.
I created a custom MyInitialViewController class, derived from UIViewController, and made this the initial view controller.
In the storyboard file, I created modal segues with appropriate names to all (in my case three) possible 'real' first view controllers.
In the MyInitialViewController class, I implemented the
- (void)viewDidAppear:(BOOL)animated;
method, to first perform the check which view to switch to, and then do the correct
[self performSegueWithIdentifier:#"NameOfSegue" sender:self];
Effectively, this makes the MyInitialViewController nothing more than a switch performed when it's brought into view. I first tried doing this when loaded because I don't care for actually seeing this view, but that did not work, while viewDidAppear does.
To make this visually smooth, I tried the following. In the properties of the segues, I disabled animation. The view I left empty, and I gave it a background color matching to that of the startup image.