I am removing login view controller from navigation stack once user gets logged in. However, the navigation bar button items added by the login view controller still remains. How to completely remove a view controller from navigation stack?
static func removePreviousFromNavigationStack(_ navVC: UINavigationController) {
var navArr = navVC.viewControllers
for elem in navArr {
if elem.isKind(of: LoginViewController.self) {
if let vc = StateData.loginVC {
vc.navigationItem.leftBarButtonItem = nil // is not working as intended
vc.navigationItem.rightBarButtonItem = nil
vc.navigationItem.title = "Foo"
}
//elem.removeFromParent()
}
}
navArr.remove(at: navArr.count - 2)
navVC.viewControllers = navArr
}
Flow: HomeVC -> ApplyVC -> LoginVC -> FormVC
After logging in to FormVC
, I call the remove method to remove LoginVC
from the stack. This removes the VC, but the nav buttons remains. If I set the nav button to nil, the ApplyVC
's leftButtonItem, back button, right button item, home button does not show. There is a transparent back button which when clicked, displays the nav bar buttons of ApplyVC
as if the LoginVC
got popped out of the view, but without any changes to the current view.
LoginViewController
'sviewDidLoad()
, I am settingStateData.loginVC = self
. The ApplyVC has navbar items added. In login VC, the same is done. But after removing the login vc from stack, the apply vc navbar items are not displayed properly as shown in the screenshot. – johndoeif let vc = StateData.loginVC { ... }
is running? That is,vc
does equalStateData.loginVC
? If so, it's not entirely clear what all you are doing, so try to put together a minimal reproducible example so folks can help you debug this. – DonMag