2014-10-11 61 views
1

我在表格视图单元格上使用自定义UIImageViewUITextField。所有的工作,但是当我选择任何细胞,imageview变得隐藏,但显示文本字段。那么问题是怎么解决的?当选择表格视图单元格时显示自定义UIImageView

这是我利用图像和文本框上的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 [email protected]"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; 
} 

回答

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被遮盖了。它不被隐藏。

+1

是的你是对的 – RaviJSS 2014-10-11 07:23:13