尽管未在tableview中实现尾随滑动操作,但滑动时会自动实现“删除"按钮 [英] Delete button is automatically implemented on swipe despite not implementing trailing swipe action in tableview

查看:112
本文介绍了尽管未在tableview中实现尾随滑动操作,但滑动时会自动实现“删除"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为表格单元格设置了领先的滑动动作,该动作已添加到购物车中.我尚未实现任何尾随滑动操作方法,但仍在获取每个单元格的删除操作.下面是我所有tableView方法的代码.我还附上了模拟器中的一张图片.

I have set a leading swipe action for tableview cell, which add to cart. I have not implemented any trailing swipe action method, still I am getting delete action for every cell. Below is my code of all tableView methods. I have also attached one image from simulator.

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 {

//对于第一个单元格

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


        return cell

    }

//对于其余单元格

    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])
}

推荐答案

解决方案是在未定义任何动作的情况下实施尾随滑动动作.代码在下面.

Solution for this is to implement a trailing swipe action without any actions defined. code is below.

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

    return UISwipeActionsConfiguration.init()
}

这篇关于尽管未在tableview中实现尾随滑动操作,但滑动时会自动实现“删除"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆