我想在tableview上删除一行,但收到​​错误?

时间:2018-11-12 19:29:32

标签: ios swift uitableview

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath){
    let cell = tableView.dequeueReusableCell(withIdentifier: "taskCell", for: indexPath) as! TaskCell
    if editingStyle == .delete {
        task.remove(at: indexPath.row)
        tableView.beginUpdates()
        tableView.deleteRows(at: cell, with: .automatic)
        tableView.endUpdates()
    }
}

错误是

  

无法将类型'TaskCell'的值转换为预期的参数类型'[IndexPath]'

3 个答案:

答案 0 :(得分:3)

您正在将cell而不是indexPath传递给deleteRows函数。

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath){
    if editingStyle == .delete {
        task.remove(at: indexPath.row)
        tableView.beginUpdates()
        tableView.deleteRows(at: [indexPath], with: .automatic)
        tableView.endUpdates()
    }
}

答案 1 :(得分:2)

您需要在代码中传递dags_folder代替import board, busio, adafruit_bno055 i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bno055.BNO055(i2c) print(min(sensor.accelerometer)) print(max(sensor.accelerometer))

在代码下面用

替换
[IndexPath]

cell

答案 2 :(得分:0)

首先,您可以为表视图添加此扩展名,然后删除行,而不是在需要重新加载如下表数据之后,

print(String(data: data, encoding: .utf8))

tableview行操作如下。

extension UITableView {
func reloadDataAfterDelay(delayTime: TimeInterval = 0.4) -> Void {
    self.perform(#selector(self.reloadData), with: nil, afterDelay: delayTime)
}
}

这是正确且迅速的完美工作。