1

I have a simple UITableView, and each cell contains a button : enter image description here

In my didSelectRowAtIndexPath method, I have the following code :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Selected cell : %@", [myArray objectAtIndex:indexPath.row]);
}

That I want :

When I click on a button (which is in a cell), I want to know what cell is selected. My problem is that when I click on a button (just on the button, not in the cell), I don't pass into the didSelectRowAtIndexPath method, unfortunately, because the cell is not selected...

How can I do that ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jonathan F.
  • 2,357
  • 4
  • 26
  • 44
  • possible duplicate of [How to get the tag values of the uibutton in uitableviewcell and aswell cel indexPath?](http://stackoverflow.com/questions/16229488/how-to-get-the-tag-values-of-the-uibutton-in-uitableviewcell-and-aswell-cel-inde) – rmaddy Oct 28 '13 at 14:13
  • I tried, but my cells are "custom cells", so I manage the button action in another class. I don't know how to get my tableView from another view... :s – Jonathan F. Oct 28 '13 at 14:57

2 Answers2

1

Make this, and you will have the index of UiCell selected!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    while (![view isKindOfClass:[UITableViewCell class]]) {
        view = [view superview];
    }
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)view];

  //Make everything that you want in here!!!!!!!
}
modusCell
  • 13,151
  • 9
  • 53
  • 80
0

that is pretty easy every time that you make a cell you set the button.tag like your index path when you click on the button you start to run your method like

- (IBAction)someMethod:(UIButton *)button

where button is the button clicked so you can get the tag and have the index :)

Popeye
  • 11,839
  • 9
  • 58
  • 91
Mirko Catalano
  • 3,850
  • 2
  • 26
  • 39