I am attempting to have the user segue to another view controller when tapping a cell. Currently I have my cell segue set up by doing the control drag in the story board to my view controller and then passing in the following code for a prepare(for segue...)
. Basically, there are my guard statements confirming I have the correct view controller and then I pass an object between them.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
switch(segue.identifier ?? "") {
case "ShowEventDetailsSegue":
guard let navVC = segue.destination as? UINavigationController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let EventDetailViewController = navVC.viewControllers.first as? EventViewController else {
fatalError("Unexpected navigation view controller: \(String(describing: navVC.viewControllers.first))")
}
guard let selectedEventCell = sender as? EventTableViewCell else {
fatalError("Unexpected sender: \(String(describing: sender))")
}
guard let indexPath = tableView.indexPath(for: selectedEventCell) else {
fatalError("The selected cell is not being displayed by the table")
}
let selectedEvent = events[indexPath.section]
EventDetailViewController.event = selectedEvent
default:
fatalError("Unexpected Segue Identifier; \(String(describing: segue.identifier))")
}
}
I know that other people recommend calling something like
DispatchQueue.main.async {
self.present(myVC, animated: true, completion: nil)
}
but when I do that, I get an error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller".
Basically, I want to be able to have the user only click one time on the cell and still be able to pass data over to the other view controller.
What is also strange is that this just started happening. I did not have this issue before today.