要取消UITableView的cell选中效果,可以在UITableViewDelegate的方法中实现取消选中操作。

首先,在UITableViewDelegate中实现以下方法:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
}

然后,在UITableViewDataSource的方法中设置UITableViewCell的selectionStyle为.none,这样在cell被选中时,不会显示选中效果。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: 'Cell', for: indexPath)
    cell.selectionStyle = .none
    // 设置cell的其他内容
    return cell
}

这样,当用户点击cell时,cell会被选中,但是不会显示选中效果。

iOS开发:如何取消UITableView Cell选中效果

原文地址: https://www.cveoy.top/t/topic/fUeb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录