I am experience a really weird thing when modally presenting/dismissing view controllers within a tab bar controller...
So here's the situation.
I have a tab bar controller (we'll call this controller "A") where the first tab is a navigation controller ("B") followed by a normal view controller ("C").
Now, if I modally present a second controller ("D") on top of "C" (within the context of "C" (meaning that "D" does not cover the nav bar or tab bar (which is accomplished by setting "C's" definesContext to true)))...
...I digress...
...and then I dismiss "D" after some time, all is well and "C" is visible again.
However, if I press a different tab, then navigate back to the first tab, and then repeat the process (present "D" on top of "C", then dismiss "D"), instead of "C" being visible once again as you'd expect, suddenly "C" is actually dismissed too! (as soon as "D's" dismissal animation completes).
So now I just have "B" showing–AKA a nav bar, tab bar, and a black screen (because the nav controller has no root view controller anymore).
Does ANYONE have any idea how/why this could possibly be happening?? I am very confident there is no other explanation or "bug" in my code as to why there is a double dismissal; it has to be something I'm not understanding about what dismiss(animated: completion: ) does within a tab bar controller setting........
EDIT (pasting code for reference):
This is controller "C":
import UIKit
class ClassworkDecisionVC: UIViewController {
@IBOutlet weak var spinner: UIActivityIndicatorView!
private var initialVCLoad: Bool = true
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard initialVCLoad else { return }
initialVCLoad = false
GoogleSignInManager.restorePreviousSignIn { [weak self] signedIn, accessToken in
guard let self = self else { return }
if signedIn {
ClassroomManager.accessToken = accessToken!
self.fromSignInVC()
}
else {
self.presentSignInVC()
}
}
}
private func presentSignInVC() {
let vc = storyboard!.instantiateViewController(withIdentifier: "SignInVC")
self.present(vc, animated: true, completion: nil)
}
// ...
}
And this is controller "D":
import UIKit
import GoogleSignIn
class SignInVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func signInBtnPressed(_ sender: GIDSignInButton) {
GoogleSignInManager.signIn(fromVC: self) { [unowned self] accessToken in
ClassroomManager.accessToken = accessToken
let classworkDecisionVC = self.presentingViewController as! ClassworkDecisionVC
classworkDecisionVC.dismiss(animated: true, completion: nil)
}
}
}