Convolution
Convolution

Reputation: 2351

Click Anywhere In TableViewCell and Focus On TextField

I have a custom tableviewcell with a label and a textfield. Right now if I click on the cell to edit the textfield, it only focuses on it if I click within the bounds of the textfield. Is there a way for me to click anywhere in the cell and immediately have it focus on the textfield, even if I click on the label?

Thanks

Upvotes: 1

Views: 654

Answers (1)

gotosleep
gotosleep

Reputation: 328

In your tableView delegate, implement this method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

Inside that method, get a reference to the selected tableViewCell using - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath and then call becomeFirstResponder on the tableViewCell's textField.

Upvotes: 2

Related Questions