目前正在 swift 中使用 UITableView。
由于我的表格单元格值是通过单击按钮附加的,因此我想找出一种方法来禁用除最后一个单元格之外的所有先前单元格的交互。
我尝试过一些基于数组的方法,但它并没有达到我想要的效果。
var disabledRows = [0,1,2]
else
{
cell.backgroundColor = UIColor.orangeColor()
}
if (contains(disabledRows, indexPath.row)) {
cell.userInteractionEnabled = false
}
else {
cell.userInteractionEnabled = true
}
这种方法的问题是我必须计算所有单元格,然后阻止最后一个单元格。
也许有一些更简单的方法?
非常感谢任何帮助。
更新 - 这是我完整的“cellForRowAtIndexPath”函数
func tableView(tableView: UITableView, cellForRowAtIndexPath
indexPath: NSIndexPath) -> UITableViewCell
{
let cell: CustomCellForTableViewTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomCellForTableViewTableViewCell
if indexPath.row % 2 == 0
{
cell.backgroundColor = UIColor.purpleColor()
}
else
{
cell.backgroundColor = UIColor.orangeColor()
}
if (contains(disabledRows, indexPath.row)) {
cell.userInteractionEnabled = false
}
else {
cell.userInteractionEnabled = true
}
let quest = arrayOfQuestions[indexPath.row]
cell.setCell(type.Grocery, optionno1:type.option1, optionno2:type.option2)
cell.mainText.text = type.Grocery
cell.optionOne.backgroundColor = UIColor.redColor()
return cell
}
最佳答案
在 cellForRowAtIndexPath: 方法中。
if (indexPath.row == yourDataSourceArray.count - 1) {
// enable cell
} else {
// disable cell
}
关于ios - 禁用除最后一个单元格之外的所有 UITableView 单元格 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31967403/