UITableViewCell with UITextField losing the ability to select UITableView row?

前端 未结 5 782
萌比男神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:21

    inside the cell for row at index path add this line which is given in bold,

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
        [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
    
        amountField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 190, 30)];
        amountField.placeholder = @"Enter amount";
        amountField.keyboardType = UIKeyboardTypeDecimalPad;
        amountField.textAlignment = UITextAlignmentRight;
        amountField.clearButtonMode = UITextFieldViewModeNever; 
    
        [amountField setDelegate:self];
        [[cell textLabel] setText:@"Amount"];
    
        **for (UIView *cellSubViews in cell.subviews) {
                cellSubViews.userInteractionEnabled = NO;
        }**
    
        [cell addSubview:amountField];
        return cell;
    }
    

    try this, it will work

提交回复
热议问题