If you use the UINavigationController and you need the default iOS return button, you do not need to install it programmatically. There is literally nothing to add, it is built in by default.
By inserting the UIViewController into the navigation controller, it will end up on the navigation controller stack, and so iOS will add the navigation bar and back button when you dig into the navigation stack.
If this does not work, check the following:
That the controller you are working with is the root of the UINavigationController. You can set this by code or in a storyboard. (are you okay)
What you click from the navigation controller, not from the view controller. Essentially, you should do navigationcontroller.push() and not self.push() , otherwise it just won't work. (depends on what self here, but I'm sure your error is here)
I see that you are using presentViewController which is designed for modal presentViewController , it’s good if this is your intention, but if you need a navigation stack, why not first embed self in the navigation controller, hide its navigation bar and then just paste your next one on it controller.
Thus, you do not need to manually create this button back and let iOS handle everything.
If you have to do it this way, you can “reject” only when you “imagine” and “pop out” when you “push”. But I don’t have enough information to understand why yours is not working. Try a few things and give us more feedback. But from what I see, you are moving towards a more complex solution than necessary.
In addition, I would really start with a simple button that says “close” and see if it works that way before trying to embed it in the panel with the item. This way you solve one problem and one new concept at a time
Gil sand
source share