UITableViewCell with UITextField losing the ability to select UITableView row?

前端 未结 5 777
萌比男神i
萌比男神i 2020-12-15 07:44

I am almost done implementing a UITableViewCell with a UITextField in it. Rather then going through CGRectMake and UITableViewCe

5条回答
  •  佛祖请我去吃肉
    2020-12-15 08:14

    If the text field has userInteractionEnabled set to YES, and it fills the entire cell, you can not get the cell to listen to touch. In order to get the cell to respond to touches, you need to set the userInteractionEnabled of the text field to NO.

    Edit: And if you want to make the text field editable, when the cell is selected, add the following code in didSelectRowAtIndexPath: method,

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        // get the reference to the text field
        [textField setUserInteractionEnabled:YES];
        [textField becomeFirstResponder];
    }
    

提交回复
热议问题