First i hide all images in cell. After i click on did select row, in that cell will show image and click again it will hide image. That working. But the problem is when i click on that cell (without click again) and then click other cell, (other cell will show image) but the previous cell will not hide image.
首先,我将所有图像隐藏在单元格中。点击didselectrow后,在那个单元格中会显示图像,然后再点击它会隐藏图像。这工作。但问题是,当我单击该单元格(不再单击)然后单击其他单元格(其他单元格将显示图像)时,上一个单元格将不会隐藏图像。
This code for cell and didselectrow
这段代码用于cell和didselectrow
2 个解决方案
#1
1
take one variable who contains current show image's indexPath.row value
取一个包含当前显示图像的indexPath的变量。行值
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()
}
#2
0
In your didSelect method before make anything with your index you need to hidden image in old cell.
在didSelect方法中,在使用索引之前,您需要在旧单元格中隐藏图像。
this will hide image in your old cell
这将在旧的单元格中隐藏图像
if(index != nil){
tableView.cellForRow(at:index!) as! FailOrderNoteTableViewCell
cell.rightViewCell.hidden = true
}
And other problem in your code is that you need to set nil for index if you haven't selected cell not row 99 and section 99 that will work fine
代码中的另一个问题是,如果没有选择单元格而不是第99行和第99节,你需要为索引设置nil
#1
1
take one variable who contains current show image's indexPath.row value
取一个包含当前显示图像的indexPath的变量。行值
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()
}
#2
0
In your didSelect method before make anything with your index you need to hidden image in old cell.
在didSelect方法中,在使用索引之前,您需要在旧单元格中隐藏图像。
this will hide image in your old cell
这将在旧的单元格中隐藏图像
if(index != nil){
tableView.cellForRow(at:index!) as! FailOrderNoteTableViewCell
cell.rightViewCell.hidden = true
}
And other problem in your code is that you need to set nil for index if you haven't selected cell not row 99 and section 99 that will work fine
代码中的另一个问题是,如果没有选择单元格而不是第99行和第99节,你需要为索引设置nil