CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
11.99k stars 1.26k forks source link

Help needed with navigation controllers #691

Closed theolof closed 7 years ago

theolof commented 7 years ago

I'm trying to add both a bottom navigation and a top navigation. One of my ViewControllers should have a FABMenu on it, that's why I make it an AppMenuController.

I'm just guessing, and it's not working. When I do it like this, nothing is shown in the top navigation. It is there, but no title is shown. How am I supposed to do this?

let menuController = AppMenuController(rootViewController: ViewController1())
let bottomNavigationController = AppBottomNavigationController(viewControllers: [menuController, ViewController2(), ViewController3()])
let navigationController = AppNavigationController(rootViewController: bottomNavigationController)

self.window?.rootViewController = navigationController

Definition of the controllers:

class AppMenuController: MenuController

class AppBottomNavigationController: BottomNavigationController

class AppNavigationController: NavigationController
theolof commented 7 years ago

I think I got it...

In ViewController1 I need to use menuController.tabBarController?.navigationItem to set the navigation title and menuController.tabBarItem to set the tab bar properties

In ViewController2 I need to use tabBarController?.navigationItem to set the navigation title and tabBarItem to set the tab bar properties

Correct?

theolof commented 7 years ago

I'll close this, but it's a lot of work setting the title of the navigation. That's maybe iOS, and not Material? Let me know if there is an easier way. In one ViewController, I need to do this:

        let navItem = tabBarController?.navigationItem
        navItem?.title = "TITLE"
        navigationItem.title = "TITLE"

because the tabBarController isn't always there (multiple ways of reaching the ViewController). And in another ViewController I need to do this:

        let navItem = menuController.tabBarController?.navigationItem
        navItem?.title = "TITLE"

since the ViewController is wrapped in a MenuController.

daniel-jonathan commented 7 years ago

So the way I understand setting the title with a UINavigationController is that you need to always set the value in the latest rootViewController. In your original setup:

let navigationController = AppNavigationController(rootViewController: bottomNavigationController)

the rootViewController is the bottomNavigationController, so the title should be set there. If you don't want to set it there, and want to set it in a deeper nested view controller, you would need to climb the hierarchy to that rootViewController. Maybe we could simplify this, as it is an iOS thing, and Material subclasses UIKit. If we could think of a design, we can then build it out. Let me know and sorry for the late reply on this issue.