如果出现错误,我想验证 UITextField 并显示 UIAlertView。
以前我使用下面的代码。它与 2 个 UIExfields 完美配合,但对于许多 UITextfield,这是不可能的。
任何提示如何显示 UIAlertView 来验证我的 UIExfields ?
- (void)processFieldEntries {
NSString *usernameString = usernameField.text;
NSString *passwordString = passwordField.text;
NSString *firstNameString = firstNameField.text;
NSString *nameString = nameField.text;
NSString *cityString = cityField.text;
NSString *errorText = @"Enter";
NSString *usernameBlankText = @" a username";
NSString *passwordBlankText = @" a password";
NSString *prenomBlankText = @" a firstname";
NSString *nomBlankText = @" a name";
NSString *joinText = @", ";
BOOL textError = NO;
if (identifiantString.length == 0 || motDePasseString.length == 0 || prenomString.length == 0 || nomString.length == 0 || idPoubelle.length == 0) {
textError = YES;
if (usernameString.length == 0) {
errorText = [errorText stringByAppendingString:usernameBlankText];
}
if (usernameString.length == 0 || passwordString.length == 0) {
if (usernameString.length == 0) {
errorText = [errorText stringByAppendingString:joinText];
}
errorText = [errorText stringByAppendingString:passwordBlankText];
}
}
if (textError) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertView show];
return;
}
}