尽管没有在 tableview 中实现尾部滑动操作,但在滑动时会自动实现删除按钮

Par*_*kia 0 xcode uitableview ios swift

我已经为 tableview 单元设置了一个领先的滑动操作,它添加到购物车。我还没有实现任何尾随滑动操作方法,但我仍然为每个单元格执行删除操作。下面是我所有 tableView 方法的代码。我还附上了模拟器中的一张图片。

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

}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if (indexPath.row == 0) {
        return 267
    }
    else {
        return 85
    }
}

//tableview methods

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Run Code Online (Sandbox Code Playgroud)

// 对于第一个单元格

    if (indexPath.row == 0){
    let cell = storeInfoTable.dequeueReusableCell(withIdentifier: "storeinfocell1", for: indexPath) as! CustomStoreInfoTableOneViewCell


        return cell

    }
Run Code Online (Sandbox Code Playgroud)

// 对于剩余的单元格

    let cell = storeInfoTable.dequeueReusableCell(withIdentifier: "storeItemCell", for: indexPath) as! StoreItemsTableViewCell
    cell.storeItemCellView.layer.cornerRadius = 5.0


    return cell[![enter image description here][1]][1]

}


@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    if (indexPath.row == 0) {return nil}

    let addToCart = UIContextualAction(style: .normal, title: "Add to Cart") { (action, view, nil) in
        print("Added to cart")
        let cell = self.storeInfoTable.cellForRow(at: indexPath) as! StoreItemsTableViewCell

        if (Int(cell.numberOfItem.text!)! == 0) {
            self.view.showToast(toastMessage: "Items must be atleast one", duration: 1.5)
        }
        else {
        self.view.showToast(toastMessage: "Successfully added to cart", duration: 1.5)
        }
    }
    addToCart.title = "Add to Cart"
    addToCart.backgroundColor = #colorLiteral(red: 0.3647058904, green: 0.06666667014, blue: 0.9686274529, alpha: 1)
    addToCart.image = UIImage(named: "cart")



    return UISwipeActionsConfiguration(actions: [addToCart])
}
Run Code Online (Sandbox Code Playgroud)

Par*_*kia 6

对此的解决方案是在没有定义任何操作的情况下实现尾随滑动操作。代码如下。

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    return UISwipeActionsConfiguration.init()
}
Run Code Online (Sandbox Code Playgroud)