Vinod Kumar Vinod Kumar - 6 months ago 10
Objective-C Question

SKSTableView Got wrong Indexpath when clicked Button inside SubRowAtIndexPath

I am using

SKSTableView
control.I have added button on cell.I have facing one issue When i clicked on button then i got wrong row and subrow.

- (IBAction)btnPickListPressed:(id)sender
{
UIButton *btn=sender;
PicklistTableViewCell *cell = (PicklistTableViewCell *)btn.superview.superview;
NSIndexPath *indexPath = [self.tblView indexPathForCell:cell];
NSLog("%@",indexPath.row);
NSLog("%@"indexPath.subRow);
}

Answer

First copy below code and open SKSTableView.h

- (NSIndexPath *)correspondingIndexPathForRowAtIndexPath:(NSIndexPath *)indexPath

paste this below to @interface SKSTableView : UITableView in SKSTableView.h

and replace your action method code to this:

UIButton *btn=sender;
PicklistTableViewCell *cell = (PicklistTableViewCell *)btn.superview.superview;
NSIndexPath *indexPath = [self.tblView indexPathForCell:cell];
NSIndexPath *correspondingIndexPath = [self.tblView correspondingIndexPathForRowAtIndexPath:indexPath];
NSLog("%@",correspondingIndexPath.row);
NSLog("%@"correspondingIndexPath.subRow);