Hina Khan Hina Khan -4 years ago 87
Objective-C Question

In SWTableViewCell, UtilityButtons not responding to setTag Property

I am using SWTableViewCell to override Standard TableViewCell to show its swipeable Left & Right Utility Buttons,
I am able to access storyboard segue or I am able to segue to detailViewController.

However I've issue with utility buttons


How can I access UitlityButtons row's IndexPath whereas I've already tried following.

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSLog(@"selected favourite button tag %ld",(long)indexPath);

In simulator it gives me same result each time for each of the row.

selected favourite button tag 0

Any solution to get button's "
" property to access index path of the row for those utility buttons in SWTableViewCell when pressed just like in normal tableview


How to access setTag Property of Utility buttons to access indexPath of the row containing that specific button when pressed.

Answer Source

You must make use of SWTableViewCellDelegate. While returning the cell in the cellForRow method of UITableViewDataSource set the delegate of the cell to be your view controller (cell.delegate = self) and implement the SWTableViewCellDelegate protocol.


- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index;
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index;

In either of these two delegate methods you may access the indexPath of the cell whose utitlity button is pressed ike so:

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"Index path: %@", indexPath);

Here you have the indexPath.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download