3

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

Swapstar
  • 223
  • 2
  • 10

1 Answers1

1

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.

Community
  • 1
  • 1
Orion Cygnus
  • 168
  • 1
  • 8
  • refer to this: https://stackoverflow.com/questions/44160137/how-to-create-viewcontrollers-without-storyboard-and-set-one-as-delegate-of-the – Orion Cygnus Jan 08 '20 at 13:28
  • That talks about pushing view controller. My issue is with presenting modally. – Swapstar Jan 09 '20 at 10:47