user3491942 user3491942 - 1 year ago 174
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];
case 2:
[self.navigationController popToRootViewControllerAnimated:YES];


Answer Source

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 you should set keyboardType property once [[UIAlertView alloc] init]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download