kironet
kironet

Reputation: 935

Swift - popViewController after Dismiss

I'm trying to dismiss viewcontroller presented as modal("Present Modally") and then popViewController in navigationController. Here is my storyboard, I want to go from QRScanner VC to Monitoring VC.

enter image description here

Here is how I'm presenting QRScanner VC in Add Device VC:

let storyboard = UIStoryboard(name: StoryboardIDs.MainStoryboard, bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: VCIDs.QRDeviceScannerVC) as! QRDeviceScannerVC
controller.deviceName = deviceNameTxt.text
present(controller, animated: false, completion: nil)

Here is how I'm trying to go back to MonitoringVC:

self?.navigationController?.popViewController(animated:true)?.navigationController?.popViewController(animated: false)

Also tried:

self?.dismiss(animated: true, completion: {
    self?.presentingVC?.navigationController?.popViewController(animated: false)
})

It always goes to the Add Device VC instead of Monitoring VC

Upvotes: 0

Views: 1025

Answers (2)

matt
matt

Reputation: 535201

Use an unwind segue, with the unwind target method located in the Monitoring VC. All the right stuff will just happen as if by magic.

Upvotes: 1

m1sh0
m1sh0

Reputation: 2351

You can try with

self?.dismiss(animated: false, completion:nil)
self?.presentingVC?.navigationController?.popViewController(animated: true)

Just check if you have reference to the navigation controller

Upvotes: 0

Related Questions