user3491942 user3491942 - 4 months ago 36
iOS Question

UIAlertView textfield keyboard type

I having problem in displaying the textfield keyboard type in the alertview. I want to display numberpad keyboard but it not working.

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

switch (alertView.tag) {
case 1:
if (buttonIndex == 0) {
UITextField *textField = [alertView textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeNumberPad;
[self performSelectorOnMainThread:@selector(ProcessDeleteTransaction:) withObject:textField.text waitUntilDone:NO];
}
break;
case 2:
[self.navigationController popToRootViewControllerAnimated:YES];
break;
default:
break;
}


}

Answer

As you know, - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex is a delegate method called when the user clicks a button on an alert view, but the textField.keyboardType should be set before becomeFirstResponder..so you should set keyboardType property once [[UIAlertView alloc] init]

Comments