Is it possible to push 2 separate instances of a UIViewController on a UINavigationContoller stack

Question

I have a generic UIViewController which has multiple uses. It can be instantiated for 6 different ways as it is designed to be very generic. Let us call this multipurpose viewcontroller as MultiPurposeViewController.

Type1VC = MultiPurposeViewController()// initiated differently
self.navigationController.push(Type1VC)

Inside Type1VC:

Type2VC = MultiPurposeViewController()// initiated differently than before
self.navigationController.push(Type2VC)

Is it allowed to do an operation with a navigation controller?

Edit:

  • Will such an operation cause any memory issues?
  • Is such an operation allowed when dealing with UINavigationController stack?
  • Has anybody encountered such a scenario of stacking multiple instances of the same UIViewContoller onto a UINavigationController stack without having any memory leaks?

Show source
| ios   | swift   | uiviewcontroller   | uinavigationcontroller   2017-09-05 21:09 1 Answers

Answers to Is it possible to push 2 separate instances of a UIViewController on a UINavigationContoller stack ( 1 )

  1. 2017-09-05 21:09

    From Official Apple Doc it is clearly mention :

    To implement a navigation interface, you must decide what data to present at each level of your data hierarchy. For each level, you must provide a content view controller to manage and present the data at that level. If the presentation at multiple levels is the same, you can create multiple instances of the same view controller class and configure each one to manage its own set of data. For example, the Photos app has three distinct presentation types.

    You can read more by following : https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html

    Hope this will give you complete idea about your issue. Feel free to comment.

Leave a reply to - Is it possible to push 2 separate instances of a UIViewController on a UINavigationContoller stack

◀ Go back