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

后端 未结 4 796
醉话见心
醉话见心 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 06:51

    if your doneEditing: looks like this doneEditing:(id)sender then you can say:

    UITextField *field = (UITextField *)sender;
    NSString *myText = field.text;
    

    EDIT:

    To access a UITextField without setting as an instance variable you need to tag it when you create it:

    [textField setTag:1];
    

    then whenever you want to access it you can get it from its parent view by the tag:

    UITextField *myTextField = [scroller viewWithTag:1];
    NSString *myString = myTextField.text;
    

    in your case, set the tag to i+1 for example to have all the textfield with unique tags.

提交回复
热议问题