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

后端 未结 4 799
醉话见心
醉话见心 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:47

    You could use something like this to loop through all UITextFields that are subviews of self.view and add their text to a NSMutableArray:

    for (UITextField *field in self.view.subviews) {
        if ([field isKindOfClass:[UITextField class]]) {
            if ([[field text] length] > 0) {
                [someMutableArray addObject:field.text];
            }
        }
    }
    

提交回复
热议问题