0
パスワードを要求する警告ビューを作成しましたが、「続行」ボタンをクリックしたときにのみメソッドを呼び出す方法が分かりませんか?UIAlertViewボタンからメソッドを呼び出す
これは私のコードです:
-(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;
}
//アクションである場合にのみ、あなたがクリックした後、私は、呼び出したいボタンを有効にします私はこの1つの内側に「DisplayMessageと」と呼ぶと思うが、私はit's正しい場合はそれを行う方法を知っているか、またはドント
-(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;
}
}
を「続行」 。
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1){
// call displayMessage, sends and error.
}
}
あなたの要件に応じて代理人の方法を呼び出す必要があります。 - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex あなたのアプリはクラッシュする予定ですか?その後、デバッグモードでアプリを一度実行すると、デリゲートメソッドまたはdisplaymessageメソッドでクラッシュするアプリケーションが見つかります –
"displayMessage"メソッドを忘れていますが、それを行う最良の方法ではないかもしれません。 - (IBInction)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //ユーザーがOK /キャンセルボタンのいずれかをクリックした場合 if(buttonIndex == 1){ _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; } } – unixeO