Romowski Romowski - 10 months ago 75
iOS Question

How to get UITableView's row and section by UIButton tag?

There is

which contain

In my cellForRowAtIndexPath:

cell.toCartBtn.tag = indexPath.row;
[cell.toCartBtn addTarget:self
action:@selector(toCart:) forControlEvents:UIControlEventTouchDown];

In toCart method I need to get row and section by tapped button tag. How can I do it?


See this code

- (void)toCart:(id)sender
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    if (indexPath)