Joe
Joe

Reputation: 8986

NavigationBar not showing on TableviewController in swift

I have a CollectionView running in my project and the collectionViewController connected to another tableview using custom segue as follows.

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    selectedMenuItem = indexPath.row

    //Present new view controller
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)

    var destViewController : UINavigationController


    switch (indexPath.row) {
    case 0:
        destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("NewTableView") as UINavigationController
        break
    default:
        destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("NewTableView") as UINavigationController
        break
    }
    self.presentViewController(destViewController, animated: true, completion: nil)


}

above code populating my NewTableview successfully but the tableview missing navigation bar completely.

so far my tries as follow...

i don't know what i am missing (any delegate method).and i noticed the newTableView data loading from the bottom with animation...

i wondering is there any way to put a navigation programmatically with back button behaviour...

Thanks in Advance.....

Upvotes: 0

Views: 598

Answers (1)

the_critic
the_critic

Reputation: 12820

You'll have to instantiate the navigation controller, not the actual view controller from your storyboard. So instead of instantiating NewTableView (the view controller you want embedded in the navigation controller), you should add an identifier to your UINavigationController so that it will be instantiated instead of the view controller itself.

Just imagine that you reuse the NewTableView controller which does not require a navigation controller as its root, how would iOS be aware of that ? So add an identifier to your hosting UINavigationController and instantiate that. The navigation controller has a root dependency on the rootViewController which will be shown by default, so you only need to display the UINavigationController and the NewTableView controller will be shown based on the dependency it has with the navigation controller.

Upvotes: 1

Related Questions