How can I read UITextField value in an IBAction. I'm creating UITextField programmatically

后端 未结 4 839
醉话见心
醉话见心 2021-01-15 06:30

How can I read UITextField value in an IBAction? I\'m creating UITextField programmatically. So I can\'t set @property an

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 07:06

    NSString *value = sender.text;
    

    If inside an IBAction, of course.

    Which ignores that there is a set of text fields, and a single button action.

    The simplest solution to the overall problem would be to store a set (or array) of text fields in an instance variable, and iterate over that set in the button action. But that is a rather coarse approach; it is probably better to use the text field delegate method and store text values directly in an array, using the button to trigger the save.

    In addition, Apple HIG would tell you that you should update your data model as the text fields are edited, rather than use a "Save" button - which is poor UX design - unless, of course, the values of individual fields can interact.

提交回复
热议问题