Ben Thompson
Ben Thompson

Reputation: 4833

How to control editing of UITextFields within custom UITableViewCell

I have a custom (subclass of) UITableViewCell with multiple UITextFields in it.

I would like to make it so that when the TableView is in editing mode, clicking the UITextField will enable editing of the TextField. However, when not in editing mode, clicking the cell (or any UITextField within it) selects the cell so I can control behavious through the didSelectCellAtIndexPath method.

What is the best way to go about this?

Many thanks in advance

Upvotes: 0

Views: 1187

Answers (1)

bontoJR
bontoJR

Reputation: 7045

The best way (and most elegant) is to override setEditing:(BOOL)editing animated:(BOOL)animated method of the cell:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    self.textField.enabled = editing;
}

Remember to call super if you need to inherit the behavior of the common UITableViewCell

Upvotes: 3

Related Questions