Search code examples
iosuitableviewsegueuistoryboardsegue

Button in UITableViewCell — identify cell when button is pressed in prepareForSegue


Sorry for the long title!

The issue here is pretty simple and it's something that I don't have a workaround for — well unless I write redundant code and GUI stuff.

Consider two UITableViewCells that have the same cell identifier — basically they look the same but have different kinds of data. Consider the Apple Store app. In the featured section — you have 'Best Games' and 'Best Apps' tableview cells. They both have a 'See All' option. This is pretty similar to what I have.

I wish to identify from which cell was this 'See All' button pressed. (Considering, I have a single segue going to another view controller when either of the 'See All' buttons are pressed.)

Note: I don't want to make another UITableViewCell. I can but I don't want.


Solution

  • -(void)yourButtonPressed:(id)sender
    {    
    
        CGPoint hitPoint = [sender convertPoint:CGPointZero toView:tableView];
        NSIndexPath *hitIndex = [tableView indexPathForRowAtPoint:hitPoint];
        NSLog(@"%i",hitIndex.row);
    
    }
    

    This is the best way to get " the button's row "