Search code examples
iosios4first-responder

I want a UItextField that is in UITableViewCell to become first responder only when the cell touched


This is what I'm trying to achieve:

I want a UITextField that is in UITableViewCell to become first responder only when the cell touched. I would like the text field to become the first responder only when I set it to first responder in the method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath`

Any idea how I can achieve this? When the textfield is touched directly, tableView:didSelectRowAtIndexPath: is never called.

Thanks in advance.


Solution

  • I guess, u have a custom UITableViewCell. In that u could have a UITextField member. Right?

    In the custom cell class, override the method,

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated:

    In that , if selected == YES, then make the text field as first responder. Else , resign the first responder.