【发布时间】:2016-09-17 10:10:26
【问题描述】:
我有一个 UITableView,它有原型 cells,其中包括一个滑块和旁边的 textfield。随着滑块值的变化,textview 内的值也会发生变化。它工作正常,除了当表格大小增加时,向下滚动时生成的新cell 已经显示了第一个单元格的值。我确实意识到这与dequeueReusableCellWithIdentifier 函数有关,因为cells 被重用了。如何避免这种情况?
这是代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("infoCell") as! InfoCell
cell.dressLabel.text = inputArrayFortableView[indexPath.row]
cell.uiSlider.maximumValue = 100
cell.uiSlider.minimumValue = 0
cell.uiSlider.continuous = true
cell.uiSlider.addTarget(cell, action: #selector(cell.uiSliderSetValue), forControlEvents: .ValueChanged)
if(cell.DressTextField.text != "")
{
cell.uiSlider.setValue(Float(cell.DressTextField.text!)!, animated: true)
}
print("outside uisliderSetvalue")
cell.uiSlider.tag = indexPath.row
print(cell.uiSlider.tag)
return cell
}
我附上截图。请记住,当我向下滚动时,新单元格的值与第一个单元格的值相同,生成的第二个单元格的值与第二个相同,依此类推。
【问题讨论】:
-
在不知不觉中显示
cellForRowAtIndexPath的代码会帮助你。
标签: ios swift uitableview uislider