First, you specify your controller class as your delegate to the table, via InterfaceBuilder, or from code
tableView.delegate = self;
and in your controller class implement the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%d", indexPath.row); // вот в вашем indexPath будет информация об индексе ячейки и об индексе секции UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // непосредственно ваша ячейка }
Option two, if you need it through the touch event
Create a UITapGestureRecognizer in the controller and set a method for it that will be called upon tapes; this method must be defined in the class that you pass as the target, in our case it is self
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tableTapped:)]; tapRecognizer.numberOfTouchesRequired = 1; [self.tableView addGestureRecognizer:tapRecognizer]; [tapRecognizer release];
And in the tapa handler, you already calculate the desired cell.
- (void)tableTapped:(id)sender{ UITapGestureRecognizer *rec = (UITapGestureRecognizer *)sender; CGPoint tapPoint = [rec locationInView:self.tableView]; NSIndexPath *path = [self.tableView indexPathForRowAtPoint:tapPoint]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path]; }