My variable value is different than the value the prepareForSegue takes when transferring?

前端 未结 2 1138
既然无缘
既然无缘 2021-01-23 08:46

Essentially, my variable (playerErrors) is updated by a button push and then the view controller is segued to the next with data transferring. However, the variable\'s value (wh

2条回答
  •  渐次进展
    2021-01-23 09:16

    You aren't calling peformSegueWithIdentifier:sender anywhere in your code, so I assume that you are triggering the segue directly from the action outlet in Interface Builder.

    This won't work where you need to execute some code on the button press, since the segue may occur before the @IBAction method executes.

    You should remove the segue from the action outlet, create a segue from your View Controller object in Interface Builder, give this segue an identifier and the you can initiate it from your @IBAction method using performSegueWithIdentifier:sender.

    Also, for readability and maintainability, I strongly suggest you create a class to store the player state and then you can just pass an instances of this class rather than 16 separate variables

提交回复
热议问题