designatednerd / DNSSwipeableTableCell

UITableViewCell subclass to add multiple buttons to a swipe-under menu like iOS 7 Mail.
MIT License
175 stars 24 forks source link

numberOfButtonsInSwipeableCell: should be numberOfButtonsInSwipeableCell:index: #5

Closed mergesort closed 10 years ago

mergesort commented 10 years ago

When using Apple's datasource/delegate pattern, and keeping them separate, if you have a variable number of buttons per cell (maybe some cells have 1 button, some have 2, some 3), it is impossible to tell which cell you are referring to in numberOfButtonsInSwipeableCell: without having the tableView to reference.

In the sample, it is done as so: NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cell.center];

but if it was a true datasource, it would not need a reference to the tableView to know what index was the one being referred to.

In my code, I have a tableViewDataSource which is separate from the tableViewController (as it backs multiple different tableViewControllers), so it is currently impossible to figure out how many buttons to display depending on certain conditions of the items in my dataSource.

Otherwise, this control has been a gem, thanks so much! Joe

designatednerd commented 10 years ago

The problem with this is that the only other reliable way I've found to get this to fire is to store the indexPath on the cell, which I find a lot ickier.

You can pass a reference to your tableView as a property or an init/factory method parameter to your Table View Data Source. I know in the separate dataSources I use I generally have a reference to the tableView for problems such as this.

I'm certainly open to other suggestions though.

mergesort commented 10 years ago

Hm, I've been thinking about it and I suppose you're right, I can't think of any better idea really. I've started keeping the methods in my datasource, passing in a tableview as a reference. Thanks for the advice!