3
votes

I have a tab bar controller. In that the first tab is a navigation controller. Lets call it controller A. I am then pushing another view controller on it. Lets call it controller B. After that I am presenting view controller C from View controller B. Now I want to dismiss only the view controller B.

Tab Bar - A(Navigation Controller's root vc) -> Push VC -> B -> Present VC -> C

A to B is going using self.navigationController.pushViewController(animated: true, completion: nil)

B to C is going like this
let vc = CViewController() vc.modalPresentationStyle = .fullScreen self.present(vc,animated: true,completion: nil)

Now When I use self.dismiss(animated: true, completion: nil) in View Controller C. It goes back to the root view controller i.e vc A. I want it to go to VC B.

Video of issue

1
When you call self.dismiss, you are not calling dismiss on C, but on B. Have you tried popViewController?Orion Cygnus
I have written the dismiss code in vc C. And pop view controller won't work because C is presented modally not pushedSwapstar
I presume you have tried "vc.dismiss()" instead of self.dismiss() ?Orion Cygnus
Yes already tried thatSwapstar
can you add screenshot of your storyboard?Ketan Parmar

1 Answers

1
votes

After a bit of thought, I replicated what you were trying to do and figured out the problem is not with calling dismiss. It is with the way you called that View Controller in the first place. Change your "B to C" code a little bit.

Instead of:

let vc = CViewController()

vc.modalPresentationStyle = .fullScreen

self.present(vc,animated: true,completion: nil)

use:

let sb : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(identifier: "C")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)

You would have to specify the identifier of your view controller in the storyboard, (Storyboard ID)

Now when you call self.dismiss(), it should only close C. I have tested this on my computer with Xcode 11.1.