Я создал Alert View, который запрашивает какой-то пароль, но мне интересно, как вызывать метод, только когда нажата кнопка «Продолжить»?
Это мой код:
-(IBAction)setUserAlert:(id)sender{
UIAlertView *setPassword = [[UIAlertView alloc] initWithTitle:@"Insert Password" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
//The password isn´t visible.
setPassword.alertViewStyle = UIAlertViewStyleSecureTextInput;
[setPassword show];
// Call the method that i want to call only after you click "Continue".
[self displayMessage:(UIButton *)sender];
}
}
// Включить кнопку только при длине> = 6 и совпадении пароля
-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{
//Defining the password
NSString *password = [[NSString alloc]initWithFormat:@"12345678"];
UITextField *setPassword = [alertView textFieldAtIndex:0];
if ([setPassword.text length] >= 6 && [setPassword.text isEqualToString:password]){
return YES;
}
return NO;
}
// Действие, которое я хочу вызвать, после нажатия кнопки «Продолжить»
-(IBAction)displayMessage:(UIButton *)sender{
if ([sender.currentTitle isEqualToString:@"YES"]){
_user.text = [[NSString alloc]initWithFormat:@"Hola Mony"];
_imageUser.hidden = YES;
_goodUser.hidden = NO;
backgound.hidden = YES;
yesButton.hidden = YES;
noButton.hidden = YES;
_userLabel.hidden =YES;
}else{
_user.text = [[NSString alloc]initWithFormat:@"You can´t play"];
_goodUser.hidden = YES;
_imageUser.hidden = NO;
yesButton.hidden = YES;
noButton.hidden = YES;
_userLabel.hidden =YES;
}
}
Я думаю, чтобы вызвать "displayMessage" внутри этого, но я не знаю, как это сделать, или если это правильно.
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1){
// call displayMessage, sends and error.
}
}