Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top