Reputation: 933
So what I'm trying to do is to send an object from a tableViewController to a collectionViewController via the sender parameter of the prepareForSegue method in didSelectRowAtIndexPath but for some reason the viewDidLoad method of that collectionViewController is being called twice before prepareForSegue. Here's the relevant code from the tableViewController:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let challenge = dataModel.challenges[indexPath.row]
performSegueWithIdentifier("ShowChallengeSegue", sender: challenge)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
...
else if segue.identifier == "ShowChallengeSegue" {
let controller = segue.destinationViewController as! ChallengeViewController
controller.challenge = sender as! Challenge
}
}
After adding a bunch of print statements the following is happening in sequence:
I have no idea why is this happening, would appreciate any help.
Edit - I replaced the collectionViewController with a tableViewController and everything seems be working fine so it might be something related specifically to UICollectionViewController.
Upvotes: 0
Views: 519
Reputation: 283
@Gerwazy Sokołowski
Check your xib file in storyboard. i think you linked segue from button or any other view. segue should be set with UIViewcontroller then you can call performSegueWithIdentifier
Upvotes: 0
Reputation: 2617
you must have took segue from cell instead of whole controller so that segue is performed twice
Please take segue from Controller then try
OR
add this code
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
return false;
}
Upvotes: 0