I have a class inherited from UITableViewController and this is also the root class. This tableView contains three custom UITableViewCells (loaded from NIB file and not subclassed) and each UITableViewCell has one UITextField. Now when I implement delegate method
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
I don’t recieve any event. This function never gets fired, I tried implementating other delegate methods too but none of them fires. How to fire these delegate methods?
I also want to override canPerformAction:sender: function for these UITextFields (Which are part of UITableViewCell);
How to do this?
The
textField:shouldChangeCharactersInRange:replacementString:method is part of theUITextFieldDelegateprotocol, so you have to set a delegate for theseUITextFields.For example, if you were creating the
UITextFields in your table view contoller code, and assuming the method was implemented in the same contoller, you could do this:However, you say you’re loading the
UITableViewCells from XIB files. You have to somehow access theUITextFields from inside the code and call thesetDelegate:method on them. You can do this by usingUIView‘ssubviewsproperty. For example:Though creating the
UITextFields in the code is much easier and more elegant, IMHO.As for overriding the
canPerformAction:sender:method, you’ll have to subclassUITextFieldfor that.