Set focus to UITextField in tableCell

前端 未结 3 1905
长情又很酷
长情又很酷 2021-02-12 07:21

I am creating a table view with UITextFields dynamically.

l_textField = [[UITextField alloc] initWithFrame:TextFieldFrame];
l_textField.tag = cellRo         


        
3条回答
  •  甜味超标
    2021-02-12 07:56

    I've faced the same issue here, even using correctly the [field becomeFirstResponder];.

    I also used tags to get the objects I have inside the cell. Your didSelectRowAtIndexPath should look like this to get the right cell:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        currentRow = indexPath.row;
    
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UITextField *indexField = (UITextField *)[cell viewWithTag:101];
        [indexField becomeFirstResponder];
    }
    

    It worked like a charm for me.

提交回复
热议问题