Can somebody help me get a reference of the previous viewController
in the UINavigationController
stack? I'm sure it's straight forward but I'm a bit tapped at the moment.
You can do it by selecting the View Controller in Storyboard editor and clicking Editor -> Embed In -> Navigation Controller. Also make sure that you have your Storyboard Entry Point (the arrow that indicates which view controller is presented first) either pointing to Navigation Controller or before it.
First thing array always starts with index 0, So to access previous you need to minus 2. Also the above code of your will crash with Array index out of Range
, if your the index of access object is less than your count. so check your condition like this
let count = viewControllers?.count
if count > 1 {
if let setVC = viewControllers?[count -2] as? SWSetVC {
//Set the value
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With