UITextField inside a UITableView
I have UITextField inside a UITableView. I've set the delegate of the text view in the cellForRowAtIndexPath method of my UITableView as follows
cell.textField.delegate = self;
but when I finished editing and press "done" I didn't get anything in my delegate method as shown below. What could be the reason?
-(void) textFieldDidEndEditing: (开发者_运维知识库UITextField * ) textField {
NSLog(@"here");
}
The textFieldDidEndEditing:
method is called after the text field resigns first responder status. To get the text field to resign first responder status, send it a resignFirstResponder
message. A good place to do that is in the text field delegate's textFieldShouldReturn:
method. It would look something like this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
When the user taps the "Done" key, the textFieldShouldReturn:
method will get called, causing the text field to resign first responder status and textFieldDidEndEditing:
to be called.
精彩评论