0
votes

I am going to do my best to explain my problem, so thanks in advance.

I usually build applications with many view controllers by having each ViewController represent a different view. Right now, I am creating a large application with many different views. I do not want to have 15+ ViewControllers in my application. I would rather have one ViewController inherit different UIViews.

For example, if on my menu bar I select the "Profile" option. I would then be taken to the selectionController and have the selectionController inherit the UIView named Settings View

For some reason upon calling the function to display the profileView nothing happens. I have implemented a similar feature like this before but not it isn't working.

HomeController

//This function is called upon menu tap

func displayController(menuOption: MenuOption, view: UIView) {
    let selectionController = UIViewController()
    selectionController.view.frame = UIScreen.main.bounds
    selectionController.navigationItem.title = menuOption.name
    selectionController.view.backgroundColor = Color.defaultBackgrondColor

    selectionController.view.addSubview(view)

    navigationController?.navigationBar.tintColor = UIColor.white
    navigationController?.pushViewController(selectionController, animated: true)
}

Menu Bar

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

//CARRY OUT ANIMATION FOR MENU BAR...

    }) { (completed: Bool) in
        let option = self.menuOptions[indexPath.row]

        switch option.name {
        case "Profile":

//This is where I call my function to display the new view

            self.homeController?.displayController(menuOption: option, view: ProfileView(frame: UIScreen.main.bounds))
        default:
            print("Staying on home page")
        }
    }
}
1
Make sure self.homeController isn't nil. If that's not the problem, make sure homeController is actually in a navigation controller.rmaddy
Home controller does come up nil when I add a breakpoint. What would the steps be to initialize the home controller?Chandler Long

1 Answers

0
votes

Have you ensured that the navigation controller has been initialized? Are you setting up your home controller using storyboards or programmatically?

If you place a breakpoint at the line in question it should give you more information on whether it has been initialized or not.