禁用除最后一个单元格之外的所有 UITableView 单元格 - Swift

Disabling all UITableView cells except the last one - Swift

目前在 swift 中使用 UITableView。

由于我的 table 单元格值是通过单击按钮附加的,所以我想找出一种方法来禁用除最后一个单元格之外的所有先前单元格的交互。

我尝试过一些基于数组的方法,但结果并不如我所愿。

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
}