Romowski Romowski - 1 year ago 130
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?

Answer Source

See this code

- (void)toCart:(id)sender
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    if (indexPath)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download