gpt4 book ai didi

ios - UIAlertView在performSelector中包含dismissWithClickedButtonIndex后不断重新出现 : withObject: afterDelay:

转载 作者:行者123 更新时间:2023-11-29 04:14:02 26 4
gpt4 key购买 nike

我有一个按钮,如果密码正确,我想在触发 segue 之前使用密码实现。当您输入错误的密码时,一切看起来都很好,我已经实现了另一个alertView来告诉用户密码是错误的。 当警报 View 弹出并在延迟一段时间后消失时,它会不断重新出现和消失,并且屏幕上无法执行任何其他操作!如何阻止再次出现?下面是我处理此问题的代码部分:

- (IBAction)editLeagues:(id)sender {

[self presentAlertViewForPassword];

}

-(void)presentAlertViewForPassword
{

_passwordAlert = [[UIAlertView alloc]initWithTitle:@"Password"
message:@"Enter Password to edit Leagues"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[_passwordAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
_passwordField = [_passwordAlert textFieldAtIndex:0];
_passwordField.delegate = self;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_passwordField.tag = textFieldPassword;
[_passwordAlert show];

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *password = [NSString stringWithFormat:@"55555"];

if ( ![_passwordField.text isEqual:password]) {

_wrongPassword = [[UIAlertView alloc] initWithTitle:@"Wrong Password"
message:@"You are not authorised to use this feature!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[_wrongPassword show];

[self performSelector:@selector(allertViewDelayedDissmiss:) withObject:nil afterDelay:2];
}
else
{
[self performSegueWithIdentifier:@"addLeague" sender:[alertView buttonTitleAtIndex:0]];
}

}

-(void) allertViewDelayedDissmiss:(UIAlertView *)alertView
{
[_wrongPassword dismissWithClickedButtonIndex:-1 animated:YES];

}


- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] >= 4 )
{
return YES;
}
else
{
return NO;
}
}

最佳答案

[_wrongPasswordmissWithClickedButtonIndex:-1animated:YES]; 将调用委托(delegate)方法alertView:didDismissWithButtonIndex:

您有两个选择:

  1. 不要设置代表密码错误警报

  2. 检查 alertView:didDismissWithButtonIndex: 中的警报是否正确

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
    if (alert == _passwordAlert) {
    NSString *password = [NSString stringWithFormat:@"55555"];
    // and so on
    }
    }

关于ios - UIAlertView在performSelector中包含dismissWithClickedButtonIndex后不断重新出现 : withObject: afterDelay:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13958673/

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