【问题标题】:Get number of text fields with text获取带有文本的文本字段数
【发布时间】:2012-04-28 17:36:54
【问题描述】:

我有一个包含大约 20 个文本字段的视图,我想检查包含文本的字段数量,而不是空的数量。最好的方法是什么?

【问题讨论】:

  • 你能说清楚吗?我不明白你问了什么!!

标签: iphone objective-c xcode ipad uitextfield


【解决方案1】:

假设文本字段在theView内:

NSUInteger count = 0;
for (UITextField *textField in theView.subviews) {
    if ([textField isKindOfClass: [UITextField class]]) {
        if ([textField.text length])
            count++;
    }
}

【讨论】:

  • +1,但您可能需要在访问 text 属性之前检查类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-17
  • 2018-10-25
  • 1970-01-01
相关资源
最近更新 更多