简体   繁体   中英

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.

-(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 "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM