I have dynamic number of textfields in my tableview, I put each textfield into a customcell in IB and load the cells by nibName.
I want to validate and show alert as user enters data, also when editingisDone I want to get the input value from user and save it to the relavent object.
for instance these are some delegate methods I can use:
- (void)textFieldDidEndEditing:(UITextField *)textField{
//save the data
}
- (IBAction)textFieldDoneEditing:(id)sender {
//hide the keypad when done is pressed
[sender resignFirstResponder];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange{}
2 questions:
1-When getting user input and validating the input how will I know which textfield’s delegate is fired since there are dynamic numbers of cells and textfields, and how can I manage this?
2-For hiding the keyboard I did this but not sure this is correct;
-In IB I opened the customcell–>right click uitextfield and connect its didEndonExit to FirstResponder‘s textFieldDoneEditing method. This works but I can’t return if I didnt add any chars to textfield. so it forces to write something in order to press the button.
With regards to your first question …
In the following code I’ll assume you have one
UITextFieldin each cell. I’ll also assume you’ve created anUITableViewCellsubclass calledCustomCellwhich contains anUITextField.