【问题标题】:Delete button is automatically implemented on swipe despite not implementing trailing swipe action in tableview尽管没有在表格视图中实现尾随滑动动作,但删除按钮会在滑动时自动实现
【发布时间】:2018-05-29 14:22:19
【问题描述】:

我为 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 {

// 对于第一个单元格

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

【问题讨论】:

    标签: ios swift xcode uitableview


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      我仍然对每个单元格执行删除操作

      通常,这是由 tableView(_:commit:forRowAt:) 的实现引起的。

      【讨论】:

        猜你喜欢
        • 2012-05-11
        • 2015-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多