I have my Storyboard with some UIViewControllers and my main UINavigationController.
Then I have a UIViewController where on tableView didSelectRowAtIndexPath I pop the UIViewController:
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!){
let provider = self.results[indexPath.row]
self.delegate?.didProviderSelected(provider)
self.navigationController?.popViewControllerAnimated(true)
}
This works fine because then I return to the previous view but what I need to return two views back.
How can I achieve this?
You can use
popToViewController(_:animated:) to pop previous two views:
if let viewControllers = self.navigationController?.viewControllers {
if viewControllers.count > 3 {
self.navigationController?.popToViewController(viewControllers[viewControllers.count - 3], animated: true)
} else {
// fail
}
}
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