It probably sounds like a weird request, but I'm trying to find a way to display a navigation controller (with a nav bar and can push and pop controllers from the stack) that is displayed in the middle of a table view and scrolls with the table view. How can I achieve this functionality?
1 Answer
When I read your question I was interested to build a demo doing thing. I tried to use container that embed a navigation controller but unfortunately it didn't work as you can't use container in repeated contents for the normal UITableView. So I used UITableViewController to use static cells and I've managed to embed a navigation controller:
The storyboard looks like this:

Method #2 incase you want to use UITableView with prototype cells:
You can create custom cell within your cells then you instantiate the navigation controller and add its view as a subview:
and in the CustomTableViewCell.swift class do the following:
class CustomTableViewCell: UITableViewCell {
var navIsAdded = false // boolean used to make sure that nav view controller is added and will not be added again
var currentNavigationController : UINavigationController! // retain the controller so that push/pop works, if you didn't retain it like this, the view will be added but no push or pop will work
func setupNavVC(){
if navIsAdded{
return
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.currentNavigationController = storyboard.instantiateViewControllerWithIdentifier("navVC") as! UINavigationController
let view = self.currentNavigationController.view
var frame = view.frame
frame.size = self.frame.size
view.frame = frame
self.contentView.addSubview(view)
navIsAdded = true
}
override func layoutSubviews() {
setupNavVC()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
