Bind properties in Swift to NSTextFields

前端 未结 2 1634
一整个雨季
一整个雨季 2021-01-25 22:29

I\'m working on a unit converter written in Swift that will automatically display the updated units within the appropriate NSTextFields. For this example, if the us

2条回答
  •  迷失自我
    2021-01-25 22:49

    You need to move the setting of the text fields' values out of viewDidLoad() to a separate method. Call that method from viewDidLoad() and also from a didSet property observer on your seconds property.

    You also need to create action methods for when the seconds, minutes, or hours fields are changed. In the action method for the seconds field, set the seconds property to secondsField.floatValue. Similarly for the other two fields. In the NIB/storyboard, connects the text fields' actions to the corresponding action method on the view controller.

提交回复
热议问题