UITextFieldDelegate vs UITextField control events

后端 未结 5 894
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 08:17

If I want to handle changes to a UITextField, such as the user typing in it; it seems like this can be done either by assigning a delegate to that text field, and then having th

5条回答
  •  不要未来只要你来
    2021-02-14 08:51

    One key difference I've found between the two approaches posed in the original question is that the delegate "shouldChangeCharactersInRange" gets called BEFORE the value in the UITextField changes. The target for UIControlEventEditingChanged gets called AFTER the value in the UITextField changes.

    In the case that you're using these events to make sure (for example) that all fields in a dialog are completely filled in before enabling a "Done" button, the target approach may work better for you. It did for me.

提交回复
热议问题