i´ve created a UINavigationController in my appdelegate and initialized it with my "modelselectionViewController". This VC has different uibuttons and when touched, a new VC ("modelViewController") is pushed on the navigationstack.
This "modelViewController" acts as my template view and has a uitabbarcontroller with different tabs. The first VC is shown immediately but any changes on the navigationcontroller doesn´t work. I would like to set the name of the title but that navigationcontroller is null.
NSLog(#"navi: %#",
self.navigationController);
If i change my code to push the different VC when touching the different tabs, navigation works but only with a third level of navigation hierachy.
I want to know if it´s possible to use only one navigationcontroller for all my different tabs. Hope i made my setup clear. Appreciate all your help. thanks
I think you might want to read Combining ViewControllers.
In general, you should have the tabbar controller as a 'root' controller, not as a 'child' controller. A quick search in Apple's doc didn't yield a formal 'forbidden', but it might be.
If you create a UITabBarController from a view that's managed in a UINavigationController (ie: if you create a navigationcontroller first, and it's still around when you create the tabbarcontroller), you're starting a fight with the frameworks. Here's the admonishment from the docs on combining viewcontroller interfaces:
An application that uses a tab bar
controller can also use navigation
controllers in one or more tabs. When
combining these two types of view
controller in the same user interface,
the tab bar controller always acts as
the wrapper for the navigation
controllers. You never want to push a
tab bar controller onto the navigation
stack of a navigation controller.
Doing so creates an unusual situation
whereby the tab bar appears only while
a specific view controller is at the
top of the navigation stack. Tab bars
are designed to be persistent, and so
this transient approach can be
confusing to users.
I read that as "if it doesn't break something that we haven't thought of on the next update, we might reject the app anyway because it's 'confusing to users.'"
I suppose you could kill the whole navigation hierarchy and the navigationcontroller if you don't need to return there (like if you just used it for a one-time setup screen). Or you can look into other options for navigating within a viewcontroller that's managed by the navigationcontroller.
One thing to try might be to navigate to a UITableView, and use its cells to push a modal view onto the navigation stack. That would be familiar to users and also jive with the intent of the navigation classes.
Related
I noticed that WhatsApp has a somewhat neat navigation behaviour on their iOS app. See the following:
There are two navigation stack behaviour here:
UINavigationController as a child of UITabBarController
UITabBarController as a child of UINavigationController
How to achieve both of this at the same time, just like WhatsApp? Does it uses a custom UINavigationController?
Currently my implementation only does number 2 and not number 1. I do know that to do number 1 I have to make the UINavigationController as a child of UITabBarController, but I will lose number 2.
However if I implemented both, I will get weird result where I get two navigation bar, like:
In the example you give, it looks like they have a UITabBarController as the root view controller. Settings is a view controller inside a navigation controller.
When you tap Data & Storage, it pushes another view controller on to the Settings nav controller's stack.
When you press Help it does the same - but the tab bar is hidden when the Help view controller is pushed on the stack.
See hide / show tab bar when push / back. swift for some ways to do this
I want to build an app using swift with the following structure:
Login/Signup screen
Home screen with slide out menu on the left
Different Pages in the menu -> same level like home screen
![Picture of the structure][1]
// Sorry not enough reputation for posting images
Here is an example, but I don't understand it.
GitHub-Link
![Picture of the controller structure][2]
Why is the Login-Screen the rootViewController of the Navigation Controller?
Why is there no "back" button on the other controllers of the menu (Friends, Profile)?
I could remove the segue from Login to Profil and the app still works fine...it's a normal push segue. I don't understand what that sequel does.
I thought every controller which is not the rootviewcontroller of the navigation controller gets pushed on the stack and a "back" button...
Should i split the Login and the Signup screen into two different controllers?
My suggestion:
1. Login screen/Signupscreen
=> Modal segue to navigation controller
2. Navigation Controller => RootViewController: Page 1
But how should I implement the Page 2, Page 3,... at the same hierarchical level as Page 1
How would you structure the controllers?
[1]: http:// i.imgur.com/qHMy6zs.png
[2]: http:// i.imgur.com/wdOGCGa.png
Looking forward to your answers!
Jan
Why is the Login-Screen the rootViewController of the Navigation Controller?
It does not have to be, it's a design decision, personally I would not do it that way.
Why is there now "back" button on the other controllers of the menu (Friends, Profile)?
Pushing a view controller onto a UINavigationController will do this automatically unless you specify that the back button should not be present in the view controller that gets pushed. UIViewControllers have a property called UINavigationItem where you can set the back button to hidden. See here.
I thought every controller which is not the rootviewcontroller of the navigation controller gets pushed on the stack and a "back" button...
Yes that's right, you sort of just answered one of your previous questions.
Should i split the Login and the Signup screen into two different controllers?
Yes that would generally be a good idea. Have a separate view and view controller for each of them. It does depend on your ui design also.
How would you structure the controllers?
It appears you have multiple menus and different sections to your app. In that case using a UITabBarController combined with multiple UINavigationControllers (one navigation controller per tab) may be one way to go about it, I've used this technique before and it works well.
If I a mistaken based on your images and you actually just have one main menu then stick to just one UINavigationController and just push and pop view controllers, have one view controller / view per view/page of your app.
Best thing is to read up about UINavigationController and UITabBarController and decide what suits how you want to layout your views / your design.
I have UITableViewController embeded in a UINavigationController in my app. When a row is selected it pushes a UITabBarController. So far so good. The problem is that some of the tabs I push more views but the tab bar gets hiden. I've tried setting hidesBottomBarWhenPushed = NO, but it doesn't work.
I'm using XCode 4 with storyboard
Any ideas?
I've had this problem in one of my apps (though it was in iOS 4.x, using nibs not storyboard).
What I did to solve it: You want to have the root controller for each tab (the one with tabitem, etc) be a navigation controller - and when you push new views onto this navstack, they will respect the top navigation bar and bottom tab bar (they may actually display two navbars, so you have to be careful, but generally this is the way to go.)
first of all you might want to take a look at this
viewController: The view controller that is pushed onto the stack. It
cannot be an instance of tab bar controller.
so pushing an instance of tab bar controller is not recommended. There's a good reference there that might accomplish the task you wanted ill just provide the link here
I am trying to write an iPhone app that has both a UITabBar controller (and its associated views) and a plain vanilla view controller that is not part of the TabBar (i.e. an initial config page that only gets displayed the first time the app is run).
I am able to put a Tab Bar Controller and a View Controller in MainWindow.xib and shuffle between the two in the app delegate.
While this works I'm wondering if this is the best way to be implementing this.
It doesn't feel very "MVC-ish" to me but I think the two different controllers both need to be root (?)
I don't know how else I would do it.
If the config page is really only a "run once" affair, you could just pop it as a modal view from within the tab bar controller via the presentModalViewController:animated: method. (If on the other hand the config page is ever likely to be required in the future, I'd just add it as another option on the UITabBar.)
You would make the tabbarcontroller the default view. And present the viewcontroller modally in viewWillAppear or similar method. Then when you want to switch to the tabbar, you'd dismiss the modal view controller.
I'm trying to write an application that uses a navigation bar and tab bar in what (I'm gathering) is an unusual manner.
Basically, I've got several "pages" ("home", "settings", etc) that each have their own tab. I'd also like to have it so that the "home" page is the root view of the navigation bar, and the other pages are the second-level views of the navigation bar. That is, I should be able to navigate to any page by clicking the appropriate tab bar item, and should be able to navigate to the home page from any other page by clicking the navigation bar's back button.
Currently, I have a UINavigationBar (through a UINavigationController) and a UITabBar (through a UITabController) as children of a UIView. The various pages' view controllers are set as the tab controller's viewControllers property, and the home page's controller is also set as the navigation controller's root view. Each page view's tag is set to its index in the tab control. I have the following logic in the tab controller's didSelectViewController delegate method:
- (void) tabBarController:(UITabBarController*) tabBarController
didSelectViewController:(UIViewController*) viewController
{
if ([navController.viewControllers count] > 1)
[navController popViewControllerAnimated:NO];
[navController pushViewController:viewController animated:YES];
}
Also, in the navigation controller's didShowViewController delegate method, I have the following code:
- (void) navigationController:(UINavigationController *) navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
tabController.selectedIndex = viewController.view.tag;
}
The problem that's occurring is that when I run this, the navigation bar, tab bar and home page all display ok, but the tab bar will not respond to input - I cannot select a different tab.
I gather it's more usual to have the tab bar as the child of the navigation control, or vice versa. This doesn't seem to fit my approach, because I don't want to have to individually create the subordinate control each time a change occurs in the parent control - eg: recreate tab bar each time the navigation bar changes.
Does anyone have suggestions as to what's wrong and how to fix it? I'm probably missing something obvious, but whatever it is I can't seem to find it. Thanks!
EDIT: I'm guessing it has something to do with both controller's trying to have ownership of the page controller, but I can't for the life of me figure out a way around it.
Yikes. You're way out on a limb here. I've learned the hard way that UINavigationController and UITabBarController aren't very accommodating when you try to use them in nonstandard ways. UINavigationBar and UITabBar weren't designed to coexist as siblings in the view hierarchy. They really want to be distant cousins. Maybe the approach you're pursuing can be made to work somehow, but I personally wouldn't even attempt it.
With that said, I'll suggest one thing you can check, and then I'll tell you how I'd approach the problem.
Have you implemented, and are you returning YES from tabBarController:shouldSelectViewController: in your UITabBarControllerDelegate? If not, that would prevent your tabs from switching.
Assuming that won't solve all your problems, here's what I would do to get the behavior you're seeking:
Create a UITabBarController and set its view as the root view of your window.
Have a separate UINavigationController under each tab, each with its own navigation bar. (This is the standard way to use UINavigationController and UITabBarController together.)
Set a UITableViewController that displays an identical copy of your main menu table as the root view controller for each navigation controller.
When a row is selected on your "Home" view controller, switch to the associated content tab.
Set a delegate on your UITabBarController. In its tabBarController:didSelectViewController method, call pushViewController:animated:. This is similar to what you're currently doing, except you'll be calling it on (UINavigationController *)tabBarController.selectedViewController.
In the viewDidAppear:animated: of the root view controllers of your content tabs, switch to the "Home" tab. This way, when the user hits the back button to go back to "Home", it will switch to the right tab. (You may also need conditional code to prevent this from happening when the user first selects a content tab. I'm not sure.)
I'll be curious to know if Apple accepts this nonstandard behavior. Come back and let us know. Also, let us know if you get your approach working somehow.