小编mor*_*itz的帖子

表格视图:从右向左滑动以删除不显示-swift 3

我已经使用Swift 3构建了一个简单的toDoList应用。现在,我希望能够TableView通过从右向左滑动来删除我的商品。这是我找到的代码。但是当我向左滑动时,什么也没有发生。


码:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    return toDoList.count
}

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")

    cell.textLabel?.text = toDoList[indexPath.row]

    return cell
}



//
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if (editingStyle == .delete) {
        toDoList.remove(at: indexPath.row)

        UserDefaults.standard.set(toDoList, forKey: "toDoList")
        tableView.reloadData()
    }
} …
Run Code Online (Sandbox Code Playgroud)

tableview swift swift3 ios10

0
推荐指数
1
解决办法
3631
查看次数

标签 统计

ios10 ×1

swift ×1

swift3 ×1

tableview ×1