0

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 1

2

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:

http://recordit.co/EsvsyWhcLX

The storyboard looks like this: Storyboard

Method #2 incase you want to use UITableView with prototype cells:

http://recordit.co/d3yhbuJ4Ww

You can create custom cell within your cells then you instantiate the navigation controller and add its view as a subview:

Using UITableView

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
}

}
Sign up to request clarification or add additional context in comments.

1 Comment

Hey Hossam, i tried opening the link of gif you gave in your answer, but I am unable to open it, it says access denied

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.