gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:08:54 24 4
gpt4 key购买 nike

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

This code for cell and didselectrow

最佳答案

取一个包含当前显示图像的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()
}

关于swift - 单击时在单元格中显示图像并在其他单元格中隐藏图像 Swift IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41586786/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com