长按单元格时,TableView单元格背景颜色未更改

时间:2015-06-30 06:21:18

标签: ios swift cell

我已更改了表视图单元格选择背景颜色,如下所示。

true

它会改变背景颜色,但是当我长按单元格时,背景颜色保持默认(深灰色)。我想改变印刷机和长按单元格选择背景颜色。怎么做?

1 个答案:

答案 0 :(得分:3)

您必须禁用选择样式(因为选择样式包含默认的灰色)

cell.selectionStyle = .None

之后添加长按手势并对其进行操作。做所需的编码。

let longpress = UILongPressGestureRecognizer(target: self, action: "longPressGestureRecognized:")

tableView.addGestureRecognizer(longpress)

现在,使用以下代码添加longPressGestureRecognized函数: 复制

func longPressGestureRecognized(gestureRecognizer: UIGestureRecognizer) {

}

longPressGestureRecognized()函数内部,首先在表格视图中获取手势的位置以及相应的tableViewCell

longPressGestureRecognized()函数中添加以下代码: 复制

let longPress = gestureRecognizer as UILongPressGestureRecognizer

let state = longPress.state

var locationInView = longPress.locationInView(tableView)

var indexPath = tableView.indexPathForRowAtPoint(locationInView)

希望它有所帮助。

相关问题