选择表视图单元格时显示自定义UIImageView

时间:2014-10-11 06:37:00

标签: ios objective-c uitableview uiimageview

我在表格视图单元格中使用自定义UIImageViewUITextField。一切正常,但是当我选择任何单元格时,imageview会变为隐藏状态,但会显示文本字段。那么问题是什么,我该如何解决呢?

这是我在tableview上使用图像和文本字段的代码 -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellidentitifier = @"cell";
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentitifier];
    if (cell ==nil)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:cellidentitifier];

    }
    else
    {
        [cell prepareForReuse];
    }

    UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 68, 70)];
    imgview.backgroundColor = [UIColor blackColor];
    imgview.userInteractionEnabled = NO;
    imgview.layer.cornerRadius =YES;
    [cell.contentView addSubview:imgview];

    _nameTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 10, 160, 20)];
    _nameTF.placeholder =@"Name";
    _nameTF.layer.borderWidth = 1.0;
    [cell.contentView addSubview:_nameTF];
    _nameTF.delegate = self;
    _nameTF.userInteractionEnabled = NO;
    _nameTF = nil;

    _addressTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 34, 160, 20)];
    _addressTF.placeholder = @"Address";
    _addressTF.layer.borderWidth= 1.0;
    [cell.contentView addSubview:_addressTF];
    _addressTF.delegate = self;
    _addressTF.userInteractionEnabled = NO;
    _addressTF = nil;


    _PhoneTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 58, 160, 20)];
    _PhoneTF.placeholder = @"Phone";
    _PhoneTF.layer.borderWidth= 1.0;
    [cell.contentView addSubview:_PhoneTF];
    _PhoneTF.delegate = self;
    _PhoneTF.userInteractionEnabled = NO;
    _PhoneTF = nil;

    _slotTF = [[UITextField alloc]initWithFrame:CGRectMake(30, 84, 250, 18)];
    _slotTF.placeholder = @"Slot";
    _slotTF.layer.borderWidth= 1.0;
    [cell.contentView addSubview:_slotTF];
    _slotTF.delegate = self;
    _slotTF.userInteractionEnabled = NO;
    _slotTF = nil;

    return cell;
}

1 个答案:

答案 0 :(得分:2)

试试这个

 UIImageView *imgview = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 68, 70)];
    imgview.backgroundColor = [UIColor blackColor];
    imgview.layer.borderWidth = 1.0;
    imgview.userInteractionEnabled = NO;
    imgview.layer.cornerRadius =YES;
    [cell.contentView addSubview:imgview];

你选择一个单元格,你会发现imgview仍然存在 所以,我认为当选择一个单元格时,这个单元格的背景颜色会变成灰色。所以,imgview的blackColor被覆盖了。它不是隐藏的