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

This is what I am trying to achieve:

I want to UITextFieldbe in UITableViewCell, to be the first responder only by touching the cell. I would like the text field to become the first responder only when I set it to the first responder in the method:

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

Any idea how I can achieve this? When a text field touches directly, it is tableView:didSelectRowAtIndexPath:never called.

Thanks in advance.

+5
source share
4 answers

I think you have a custom UITableViewCell. That u may have a member of UITextField. Correctly?

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

, == YES, . Else, .

+2

UITextField textFieldShouldBeginEditing:; return NO, . ( NO , becomeFirstResponder .)

+1

, textField first responder, uitableviewcell, property [self.textField1 becomeFirstResponder];

. , UITableViewCells, .

textField , . tags, textField.tag == 0 , textField.tag ==1 . textFieldDidBeginEditing , .

- ?:)

+1

, UITableViewCell. hitTest:, , . , UITextField, , . , :

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if (self.editing) {
        if ([nickname pointInside:[self convertPoint:point toView:nickname] withEvent:nil])
            return [nickname hitTest:[self convertPoint:point toView:nickname] withEvent:event];

        return [super hitTest:point withEvent:event];
    }

    return [self contentView];
}

The attribute nickname, in this case, was a UITextField inside a custom UITableViewCell.

The condition around self.editing may or may not be relevant to your application. The idea here shows you how hitTest: can be used in general.

+1
source

All Articles