![](/img/trans.png)
[英]how to delete particular row in table view and edit that custom cell details
[英]How to delete table view row from custom cell?
我有一个带有两个按钮的自定义表格视图单元格。 如果任何一个被按下,我希望表格视图删除该行。 我已经知道该代码:
myArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
我只是想从我的自定义单元格中调用它。 我有这样设置:
@IBAction func handleDecline(sender: AnyObject)
{
// Remove table view row
}
@IBAction func handleApprove(sender: AnyObject)
{
// Remove table view row
}
我将如何去做?
您不应处理从单元格本身删除单元格的问题。 它违反了MVC模式。 应该将事件委托给视图控制器,并使用deleteRows
方法在其中进行处理,如下所示:
tableView.deleteRows(at: [indexPath], with: .fade)
还必须相应地更新tableView的dataSource,否则应用程序将崩溃。
在这里,您可以找到一个示例,该示例说明了如何从单元委派事件到视图控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.