单击并在其他单元格Swift IOS中隐藏图像时在单元格中显示图像

时间:2017-01-11 09:15:35

标签: swift hide show

首先,我将所有图像隐藏在单元格中。在我点击确定选择行后,在该单元格中将显示图像并再次单击它将隐藏图像。那工作。但问题是,当我点击该单元格(没有再次点击),然后单击其他单元格,(其他单元格将显示图像),但前一个单元格将不会隐藏图像。

This code for cell and didselectrow

2 个答案:

答案 0 :(得分:1)

获取一个包含当前show image的indexPath.row值的变量

 var showImageIndex : Int?

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

   let tableCell = tableView.dequeueReusableCellWithIdentifier("cellName") as? CustomCell

   if showImageIndex == indexPath.row{
      tableCell.IBimageView.isHidden = false
   }else{
      tableCell.IBimageView.isHidden = true
   }
 }

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
    showImageIndex = indexPath.row
    self.tableViewName.reload()
 }

答案 1 :(得分:0)

在使用索引制作任何内容之前,在didSelect方法中,您需要隐藏旧单元格中的图像。

这会隐藏旧单元格中的图像

if(index != nil){
    tableView.cellForRow(at:index!) as! FailOrderNoteTableViewCell
    cell.rightViewCell.hidden = true
}

您的代码中的其他问题是,如果您没有选择单元格而不是第99行,那么您需要为索引设置nil,而第99条可以正常工作