TABLEView中的Cells Backgroundcolor包含大量数据

时间:2016-01-28 18:32:14

标签: ios swift uitableview

我有一个包含多个数据的数组,其中一些数据不在屏幕之内。我写了一个方法,如果点击一行它移动到数组的末尾而另一个向上移动,同时我想改变所选行的颜色,做一个知道如何管理它? 这是我的尝试:

var dataSample = [....]

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let selectedItem = dataSample[indexPath.row]
    dataSample.removeAtIndex(indexPath.row)
    dataSample.append(selectedItem)

    let newIndexPath = NSIndexPath(forRow: dataSample.count - 1, inSelection: indexPath.selection)
    tableView.moveRowAtIndexPath(indexPath, toIndexPath: newIndexPath)

    tableView.reloadRowsAtIndexPath([newIndexPath], withRowAnimation: .Fade)

现在我尝试更改单元格颜色

    let cell = tableView.cellForRowAtIndexPath(newIndexPath)
    cell?.contentView.backgroundColor = UIColor.darkGrayColor

但没有任何反应,颜色没有改变,但是,

如果我向下滚动并看到数组的末尾,然后在最后一行之前选择一些行,则该行变为愿望颜色,但只是在边界上而不是完整

enter image description here

0 个答案:

没有答案
相关问题