Search code examples
iosuitableviewsegue

segue with protocol/delegate data passing called twice


I want to set up some data from a tableViewCell before a segue. In my table extension I overload didSelectRowAt to set that data up. This is based on advice I read to trigger the segue there with:

performSegue(withIdentifier: "itemSelected", sender: cell)

My segue from the table row selection action in the storyboard is firing and flow of execution is reaching this controller's prepare for: segue before didSelectRowAt is firing. The result is that my performSegue (and the preceding work to set it up) is handled after an initial attempt, and it looks like the destination view controller is loaded twice in quick succession -- the second one being correct.

I'm wondering how I can leave the segue defined, but remove it from the selection action on the storyboard.

ps: I know that shouldPerformSegue could be used to abort the automatic one that comes first .. but it seems like it would be even better to not have to abort it in the first place.


Solution

  • When you attach the segue to the cell selection action , the navigation occurs twice one from the attach , and the other from performSegue code inside didSelectRowAt , so you need to attach the segue to the VC itself