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?


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

How to retrieve values of dynamically created controls in code behind? code-behind dynamically-generated html-input

I intend to use Javascript to dynamically create a group of html elements (input boxes, select list, radio button, etc.) each time the user clicks "Add More" button.

How to get a frame off animated png using CSS?

css css3

Does CSS provide a way to get a specific frame from animated png (APNG, PNG), or even loop the (A)PNG only from frame A to frame B?

Regular expression for email to allow only two domain regex

I have to create a regular expression for email id like this