Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include "MPAMyViewController.h"
  2.  
  3. static NSString *MPAPasswordConfirmationAlertTitle = @"Please confirm your password.";
  4. static NSString *MPAPasswordConfirmationAlertCancelButtonTitle = @"Cancel";
  5. static NSString *MPAPasswordConfirmationAlertOkButtonTitle = @"OK";
  6. static NSString *MPAPasswordConfirmationTextFieldPlaceholder = @"Enter Password";
  7.  
  8. @interface MPAMyViewController () <UIAlertViewDelegate, UITextFieldDelegate>
  9.  
  10. @property (strong, nonatomic) NSString *errorFromRequest;
  11. @property (strong, nonatomic) UIAlertView *passwordAlertView;
  12.  
  13. - (void)processRequest:(UITextField *)passwordTextField;
  14.  
  15. @end
  16.  
  17. @implementation MPAMyViewController
  18.  
  19. - (IBAction)showPasswordConfirmationAlert:(id)sender {
  20. self.passwordAlertView = [[UIAlertView alloc] initWithTitle:MPAPasswordConfirmationAlertTitle
  21. message:self.errorFromRequest
  22. delegate:self
  23. cancelButtonTitle:MPAPasswordConfirmationAlertCancelButtonTitle
  24. otherButtonTitles:MPAPasswordConfirmationAlertOkButtonTitle, nil];
  25.  
  26. self.passwordAlertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
  27.  
  28. UITextField *passwordTextField = [self.passwordAlertView textFieldAtIndex:0];
  29. [passwordTextField becomeFirstResponder];
  30. passwordTextField.placeholder = MPAPasswordConfirmationTextFieldPlaceholder;
  31. passwordTextField.delegate = self;
  32.  
  33. [self.passwordAlertView show];
  34. }
  35.  
  36.  
  37. #pragma mark - UIAlertViewDelegate
  38.  
  39. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  40. NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
  41.  
  42. if([title isEqualToString:MPAPasswordConfirmationAlertOkButtonTitle]) {
  43. UITextField *passwordTextField = [alertView textFieldAtIndex:0];
  44. [self processRequest:passwordTextField];
  45. }
  46. }
  47.  
  48.  
  49. #pragma mark - TextField Delegate
  50.  
  51. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  52. [self.passwordAlertView dismissWithClickedButtonIndex:self.passwordAlertView.firstOtherButtonIndex animated:YES];
  53.  
  54. return YES;
  55. }
  56.  
  57. - (void)processRequest:(UITextField *)passwordTextField {
  58. NSString *password = passwordTextField.text;
  59.  
  60. // CODE: send request
  61. }
  62.  
  63. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement