I have two screens. The first is based on UITableView instance. When I tap cell, function tableView(_:didSelectRowAt:) triggers:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedEmg = selectedEmergencies[indexPath.row]
performSegue(withIdentifier: "ShowMoreInfoAboutEmg", sender: self)
}
Here is storyboard:
But in fact, the segue "ShowMoreInfoAboutEmg" duplicates itself and second screen.
I can cut performSegue(withIdentifier:sender:) and the transition between screens will work correctly. However I need to transfer data from UITableViewCell instance to remote UIViewController's property. Otherwise I get something like this:
prepare(for:sender:) starts to work earlier than tableView(_:didSelectRowAt:) and remote view controller gets nil object from cell. Any tips, guys?
The decision is found.
The simple and useful UITableView's property indexPathForSelectedRow.
I didn't touch my storyboard but I removed tableView(_:didSelectRowAt:) implementation completely and just have added one line. It's enough to use prepare(for:sender:) totally. The general implementation is something like below:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SomeCustomIdentifier" {
guard let remoteViewController = segue.destination as? CustomViewController else {
fatalError("CustomViewController instance is not found ")
}
selectedItem = items[(self.customTableView.indexPathForSelectedRow?.row)!]
remoteViewController.selectedItemFromTable = selectedItem
}
}



Maybe it will be much simpler:
P.S. Don't forget to remove segue in Storyboard and add
Storyboard IDtoEmgDetailsPresenter