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.
Related
Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you.
http://i.stack.imgur.com/IYmX2.png
http://i.stack.imgur.com/7slt5.png
The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.
A correct layout looks like this in Interface Builder :
To reproduce:
In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
Add a 3rd UIViewController next to VController1 Let's call it VController3
Wire in a segue between VController1 and VController3, for example with a button.
I hope that's clear enough
Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application
Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.
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.
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 reading a book called Beginning iPhone 3 Developement - Exploring the iPhone SDK, by Dave Mark and Jeff LaMarche. I've read about navigation controllers and multiview applications, and now I want to create my own little app, a very simple Twitter app. I want a login view, and if the login is successful I want the user to be presented a view with a tab bar, where each tab is Update, Timeline and such. Right now I'm just going for the update view.
So I thought about a navigation-based app. The first view, the login view, is on the bottom of the stack. When the user logs in, the view with the tab bar is pushed on to the stack. Then the user does whatever (s)he wants there, in the tabs. (S)he should then be able to press some kind of logout button, which pops the tab bar view off the stack, and takes the user back to the login view.
Now to my question (sorry for my long explanation): is this the way to go? If so, how do I do it? Do I create a view controller called LoginViewController, which is subclassing UINavigationController, or what?
From a UI perspective, a more fluid design might use a modal view controller.
A modal view controller pops up from the bottom of the screen and displays its own view. When this view is dismissed, it shuffles down and disappears.
In my opinion, a modal controller is a good place for a transient authentication screen — you just bring it in view, the user enters his or her info, and the view is dismissed.
On returning to the parent view controller, it checks the authentication credentials and modifies its view if authenticated (or not).
Another advantage of the modal view controller is that it is on its own navigation stack. So you don't need to push a controller, pop up and then push a different view controller. It makes for cleaner code and a cleaner interface (again, in my opinion).