Basically, I have a button that when you press it, it runs its action methond (changes a field in my Data class) and segues into another view which displays the field. After some debugging I realized that prepareSegue, and perhaps other related methods run before my button's action, and thus display the old field value instead of the new. Is there anyway around this. I was thinking maybe instead of segueing on the button press, I would create a segue to my first scene and segue to it at the end of my buttons action method, but am not sure how to set the destination of a segue made programmatically. Or is there a better way to update the field before segueing? Thanks in advance.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If the segue is happening automatically you can do the work (field update) inside prepareForSegue:
. The segue you're given in that method can provide a reference to the new controller and the sender parameter should be your button.