How can I set the value of a UILabel following a segue?

后端 未结 1 631
梦毁少年i
梦毁少年i 2020-12-19 00:44

I have a simple storyboard consisting of two UIViewControllers, with a segue connecting them.

UIVC1 --> UIVC2

I\'m trying to set a UILabel on UIVC2 to be eq

相关标签:
1条回答
  • 2020-12-19 01:07

    Your UILabel text is not being set because prepareForSegue is being called before the IBOutlet for your label on the destination view controller is connected. So at that point the label is still nil (and sending a message to nil has no effect.)

    What you should do instead is to create a new property on your destination view controller to store the string, and set this property in prepareForSegue. Then in your destination view controller's viewDidLoad method, use the value of that property to set the text property of your UILabel.

    0 讨论(0)
提交回复
热议问题