使用自定义按钮从表格视图中删除行-Swift 3 [英] Delete a row from table view using custom button - Swift 3

查看:111
本文介绍了使用自定义按钮从表格视图中删除行-Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用自定义按钮从tableview中删除行

How to delete a row from tableview using custom buttom

//CustomCell.swift

protocol FavoriteCellDelegate {
    func deleteButton(sender:CustomCell)
}

class FavoriteItemTableViewCell: UITableViewCell{
    var delegate: FavoriteCellDelegate!
    @IBAction func deleteButton(_ sender: UIButton) {
    delegate.deleteButton(sender: self)
}
}


CustomClass:UITableViewDataSource,UITableViewDelegate,CustomCellDelegate{
@IBOutlet weak var tableView: UITableView!
// all necessary functions for table view....

// Function delegated to perform action.
func deleteButton(sender:FavoriteItemTableViewCell){
    //How should I delete. How can I get index path here
}

}

问.我应该在deleteButton函数中写些什么?我无法在此处获取indexPath,因此应该怎么做.我已经在单元格中有了另一个按钮,并且委派工作正常.

推荐答案

您可以使用这样的表视点获取indexPath

you can get indexPath using table view point like this

let buttonPosition : CGPoint = sender.convert(sender.bounds.origin, to: tableview)
let indexPath = tableview.indexPathForRow(at: buttonPosition)

这篇关于使用自定义按钮从表格视图中删除行-Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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