[英]Delete UITableView row from UITableViewCell?
I'm subclassing UITableViewCell
so I can design my own cells with gestures, etc. 我将
UITableViewCell
子类化,因此可以使用手势等设计自己的单元格。
One of the things I'm trying is to delete the cell/row after swiping. 我要尝试的一件事是在滑动后删除单元格/行。
My gesture recognizers are all setup and working nicely, however I'm unsure on how to tell the UITableView
to delete this object. 我的手势识别器都已设置并且运行良好,但是我不确定如何告诉
UITableView
删除此对象。 How can I reference the parent tableView, tell it which row to delete from within the UITableViewCell
subclass? 如何引用父tableView,告诉它从
UITableViewCell
子类中删除哪一行?
Thanks 谢谢
You could define a delegate protocol in your UITableViewCell
subclass, add a method like cell:didSwipeRightToLeftGesture
, and have your cell call its delegate when that happens. 您可以在
UITableViewCell
子类中定义委托协议,添加诸如cell:didSwipeRightToLeftGesture
类的方法,并在发生这种情况时让您的单元cell:didSwipeRightToLeftGesture
其委托。 Then when your controller receives that delegate message, delete the row from the data source and update the table view. 然后,当您的控制器收到该委托消息时,请从数据源中删除该行并更新表视图。
You could also use UITableView's built-in swipe-to-delete as well. 您还可以使用UITableView的内置滑动到删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.