Reputation: 2364
I have a simple UITableView, and each cell contains a button :
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 ?
Upvotes: 1
Views: 1360
Reputation: 184
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!!!!!!!
}
Upvotes: 1
Reputation: 3850
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 :)
Upvotes: 0