iosuitextfielduitextfielddelegate

Trying to implement custom number pad for UITextField in iOS


I am working on an app where I have a UITableView that has a UITextField in each cell. The textfield is attached to each row via a custom cell. Because there is no number only keypad for the iPad, I have to implement my own (I don't have a choice here).

I have created custom buttons for this keyboard inside MainStoryboard, attached these buttons to a view that serves as a custom inputView. These buttons all call the same method which should enter the value of the label on the button, into the textfield. Unfortunately, this is not working. I am implementing the UITextFieldDelegate method:

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    
    NSLog(@"how about here?");
    return YES;
    
}

which unfortunately does not get called when I place the cursor in any of the textfields, and not when I press any of the keys on the keypad, since I don't see any output on my Xcode screen.

I attach the custom keypad to the inputView attribute of each textfield inside my "cellForRowAtIndexPath" method as follows:

_cell.textField.inputView = _inputView;

What am I doing wrong? I figure implementing the UITextFieldDelegate would be the way to go to accomplish this (which to me appears to be very straight forward). I have also included a screenshot:

enter image description here


Solution

  • Make

    textField.delegate = self
    

    or

    _cell.textField.delegate = self;
    

    Hope this works !!!