a new view controller should be added while the previous controller will be omitted swift

The problem is that you present your popOverVC from a view controller that is being dismissed, so your popOverVC will never be shown as its parent is being dismissed.

Not sure how your architecture is exactly but you would either need to use the delegate pattern to tell the parent when to segue, for example:

self.dismiss(animated: true) {
    self.delegate?.didDismiss(viewController: self)

Or to use some trick to get the top most view controller to present your popOverVC after the current view has been dismissed, ex:

self.dismiss(animated: true) {
    var topController: UIViewController = UIApplication.shared.windows.filter{$0.isKeyWindow}.first!.rootViewController!
    while (topController.presentedViewController != nil) {
        topController = topController.presentedViewController!
    topController.present(popOverVC, animated: true)

But I agree with @Paulw11, a UITabBarController seem like a much better option for what you’re trying to do.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top