Search code examples
swiftcontrollerios8navigationcontroller

How to structure controllers using swift?


I want to build an app using swift with the following structure:

  1. Login/Signup screen
  2. Home screen with slide out menu on the left
  3. 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


Solution

  • 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.