Ruslan Kuchukbaev
Ruslan Kuchukbaev

Reputation: 17

How I can instantly replace presented UIViewController?

I have implemented two different UIViewControllers, that should replace each other based on server respond and user actions. For simplicity let's think that we have two UIViewControllers with button replace with another, that should trigger this replacement.

Now I need to do that replace part, but the problem is there is some delay between dismissing one screen and showing the other. I want to somehow get rid of it. I show UIViewController modally with present method.

I thought about making these two screen as views in xib-files, and one UIViewController that will be loading these xibs, adding them as subViews and replacing one subView with another when it needs it, but maybe there is a way to do that with two UIViewControllers?

Code that I use to present controller:

let vc = UIViewController1()
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: false, completion: nil)

And to dismiss:

self.dismiss(animated: false, completion: nil)

Upvotes: 0

Views: 728

Answers (3)

Akash Soni
Akash Soni

Reputation: 535

you can add a container view and in that view you can simply add your desired controller as the child view controller official doc reference.

another reference

Upvotes: 1

steveSarsawa
steveSarsawa

Reputation: 1679

  • To Present
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
self.present(vc, animated: false, completion: nil)
  • To Dismiss
self.dismiss(animated: false, completion: nil)

First you send notification to parent class for present another 'viewController' and then dismiss current class

  • Note: Both present class method set animation false

Upvotes: 0

ellstang
ellstang

Reputation: 1

Set the present method's "animate" parameter to be false

Upvotes: 0

Related Questions