0

I am trying to fix on iOS 7+ an alert allowing me to input a 4 digit code, at the moment, the prompt appears, but the input field is blank and does not allow me to put anything in. The methods below are used to call the pin code option, starting with the segmentedAction as seen below;

-(void)segmentedAction:(id)sender{


        UISegmentedControl *control = (UISegmentedControl *)sender;

        NSString *pincode = [self.objSettingAdapter getPinCode];
        NSString *patternCode = [self.objSettingAdapter getPatternCode];
        NSInteger pincodetype = control.selectedSegmentIndex;


        if ((![pincode length]>0) && pincodetype==0) {

            [self takePinInputFromUser:@"Choose Your PIN Code"];

        }else if((![patternCode length]>0) && pincodetype==1) {

            [self takePatterInputFromUser:@"Draw Pattern"];

        }else {

            [self.objSettingAdapter setPinCodeType:control.selectedSegmentIndex];
        }

}

-(void)buttonAction:(id)sender{

    UIButton *btn = (UIButton *)sender;

    NSString *pincode = [self.objSettingAdapter getPinCode];
    NSString *patternCode = [self.objSettingAdapter getPatternCode];

    if ([btn.titleLabel.text isEqualToString:@"Reset PIN"] && (![pincode length]>0)) {

        [self takePinInputFromUser:@"Choose Your PIN Code"];

    }else if ([btn.titleLabel.text isEqualToString:@"Reset Pattern"] && (![patternCode length]>0)) {

        [self takePatterInputFromUser:@"Draw Pattern"];
    }else {

        [self.objSettingAdapter setPinCodeType:([btn.titleLabel.text isEqualToString:@"Reset PIN"] ? 0 : 1)];
    }

}


    -(void)takePinInputFromUser:(NSString *)title{

        AlertPinCode *prompt = [AlertPinCode alloc];
        prompt = [prompt initWithTitle:title message:@"\n\n" delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Done"];
        [prompt show];
    }

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{

    AlertPinCode *alertPin = (AlertPinCode *) alertView;

    if (buttonIndex != [alertView cancelButtonIndex])
    {
        NSString *userPin = [alertPin enteredText];

        if ([userPin length]<4) {

            [alertPin dismissWithClickedButtonIndex:0 animated:YES];
            [self takePinInputFromUser:@"Chose 4 Digit PIN Code"];

        }else {

            [self.objSettingAdapter setPinCodeType:0];
            [self.objSettingAdapter setPinCode:userPin];

        }
    }    

}
Hypergater
  • 559
  • 1
  • 5
  • 15

2 Answers2

0

Try the following.

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];

    __weak typeof(UIAlertController) *weakAlertController = alertController;
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        __strong typeof(UIAlertController) *strongAlertController = weakAlertController;
        UITextField *digitTextField = [strongAlertController.textFields firstObject];
        NSString *pinCode = digitTextField.text;
        NSLog(@"pin code: %@", pinCode);
        // Do something with the PIN code
    }];

    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"Input 4 Digit PIN Code";
    }];

    [self presentViewController:alertController animated:YES completion:nil];
svarad
  • 21
  • 6
-1

you can use UIAlertViewController

Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52