How do I notify the UITableViewController of events from a UITableViewCell subclass?

I have a gesture recognizer on each of the table view cells, and when they swipe one I want my delegate to notify the table view (or if there's a better way without delegates, that) so it can be deleted. But how do I know the cell's indexPath or whatever so it can be deleted?

Answers


Using a delegate is a good pattern to use for this. Your custom cell class should define a protocol and a delegate property. The view controller should set itself as the cell's delegate and the view controller should implement the cell's protocol method(s). Make sure one of the parameters of the protocol methods is the cell.

The view controller can ask the table view for the index path of the cell if that is needed. There is no need for the cell to know its index path. Since rows and sections can be added/deleted, it is bad form for a cell to be told what its index path since it could change at any time.


Need Your Help

Getting today's midnight time as UTC

sql-server sql-server-2008 sql-server-2008-r2

I have the following query which calculates today's midnight value (UTC) as a datetime:

ajax filtering and infinite scroll (php & isotope)

php ajax filtering jquery-isotope infinite-scroll

I am using the isotope plugin (http://isotope.metafizzy.co/) with the infinite ajax scroll plugin (https://github.com/webcreate/infinite-ajax-scroll). The infinite scroll works great with the isot...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.