循环遍历UITextFields
数组并检查其中是否有任何空
NSArray*textFields = ...;
textFieldHasData = YES;
[textFields enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:@""]) {
textFieldHasData = NO;
*stop = YES;
}
}];
if (!textFieldHasData) {
//Empty text fields found
}
我还想检查数据中 ALL textfields
是否为空,而不是单独检查。
答案 0 :(得分:2)
颠倒逻辑:
NSArray *textFields = ...;
textFieldHasData = NO;
[textFields enumerateObjectsUsingBlock:^(UITextField *field, NSUInteger idx, BOOL *stop) {
if ([[field text] length] > 0) {
textFieldHasData = YES;
*stop = YES;
}
}];
if (!textFieldHasData) {
// All text fields are empty
}