UIAlertViewStyleSecureTextInput
に値を入力しているときにキーボードのリターン キーをタップすると、iOS 8 でUIAlertView
呼び出しがトリガーされます。alertView:clickedButtonAtIndex:
UIAlertViewDelegate
iOS 7UIAlertViewDelegate
では、同じ条件で同じ呼び出しがトリガーされませんでした。
これが の問題かどうかはわかりませんiOS 8 or iOS 7
。しかし、私のコードは iOS 8 の期待どおりに機能しなくなりました。
コードサンプル:
#include "MPAMyViewController.h"
static NSString *MPAPasswordConfirmationAlertTitle = @"Please confirm your password.";
static NSString *MPAPasswordConfirmationAlertCancelButtonTitle = @"Cancel";
static NSString *MPAPasswordConfirmationAlertOkButtonTitle = @"OK";
static NSString *MPAPasswordConfirmationTextFieldPlaceholder = @"Enter Password";
@interface MPAMyViewController () <UIAlertViewDelegate, UITextFieldDelegate>
@property (strong, nonatomic) NSString *errorFromRequest;
@property (strong, nonatomic) UIAlertView *passwordAlertView;
- (void)processRequest:(UITextField *)passwordTextField;
@end
@implementation MPAMyViewController
- (IBAction)showPasswordConfirmationAlert:(id)sender {
self.passwordAlertView = [[UIAlertView alloc] initWithTitle:MPAPasswordConfirmationAlertTitle
message:self.errorFromRequest
delegate:self
cancelButtonTitle:MPAPasswordConfirmationAlertCancelButtonTitle
otherButtonTitles:MPAPasswordConfirmationAlertOkButtonTitle, nil];
self.passwordAlertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *passwordTextField = [self.passwordAlertView textFieldAtIndex:0];
[passwordTextField becomeFirstResponder];
passwordTextField.placeholder = MPAPasswordConfirmationTextFieldPlaceholder;
passwordTextField.delegate = self;
[self.passwordAlertView show];
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:MPAPasswordConfirmationAlertOkButtonTitle]) {
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
[self processRequest:passwordTextField];
}
}
#pragma mark - TextField Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.passwordAlertView dismissWithClickedButtonIndex:self.passwordAlertView.firstOtherButtonIndex animated:YES];
return YES;
}
- (void)processRequest:(UITextField *)passwordTextField {
NSString *password = passwordTextField.text;
// CODE: send request
}
@end