gpt4 book ai didi

ios - 同一个 UIAlertView 中显示多个错误

转载 作者:行者123 更新时间:2023-11-28 19:59:32 24 4
gpt4 key购买 nike

我在网上搜索过,但没有找到答案。在我的应用程序中,我有一个用户注册,所以我必须在接受用户之前检查输入文本字段。

这是我的代码:

- (IBAction)continueRegister:(id)sender {
if (!termsOfUseChecked)
NSLog(@"Error");
else
NSLog(@"Success");
if ([_regTelephoneNumber.text length] > 10) {
[self initWithTitle:@"error" andMessage:@"bla bla" andCancelButton:@"ok"];
}

if ([_regUserEmail.text rangeOfString:@"@"].location == NSNotFound){
[self initWithTitle:@"error" andMessage:@"bla bla" andCancelButton:@"ok"];
}
if (![_regPassword.text isEqualToString:_regConfirmPassword.text]) {
[self initWithTitle:@"error" andMessage:@"bla bla" andCancelButton:@"ok"];
}

}

-(void)initWithTitle:(NSString*)title andMessage:(NSString*)message andCancelButton:(NSString*)cancelButton;
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButton otherButtonTitles:nil, nil];
[alert show];
}

但如果发生不止一个错误,用户会收到许多弹出窗口。有什么方法可以在同一个 UIAlertview 中显示所有错误?

最佳答案

你可以使用NSArray

- (IBAction)continueRegister:(id)sender {
NSMutableArray *errorArr = [@[] mutableCopy];
if (!termsOfUseChecked)
NSLog(@"Error");
else
NSLog(@"Success");
if ([_regTelephoneNumber.text length] > 10) {
[errorArr addObject:@"Telephone Bla"];
}

if ([_regUserEmail.text rangeOfString:@"@"].location == NSNotFound){
[errorArr addObject:@"UserEmail Bla"];
}
if (![_regPassword.text isEqualToString:_regConfirmPassword.text]) {
[errorArr addObject:@"Password Bla"];
}

if([errorArr count]==0){
[self initWithTitle:@"No Error" andMessage:@"Success" andCancelButton:@"ok"];
}
else if([errorArr count] == 1){

[self initWithTitle:@"Error" andMessage:errorArr[0] andCancelButton:@"ok"];
}
else if([errorArr count] >1){

[self initWithTitle:@"Multiple Error" andMessage[errorArr componentsJoinedByString:@","] andCancelButton:@"ok"];
}

}

关于ios - 同一个 UIAlertView 中显示多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24849723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com