Reputation: 8986
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 embedded new navigationController to collectionView results remain unchanged.
i embedded new navigationController to NewTableView results remain unchanged.
i tried unwind segue method using custom navigation button action method.so i insert the navigation bar item and button to the view and Method works,but it works strangly when navigation bar button pressed it takes me to my main collection view controller thats what i what.but i have another back button appears in collection view rowindex item name on it.when i pressed the button it take me back to the NewTableView its like looping through.
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
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