Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView DidSelectRowAtIndexPath?

I have a table view with a few items (all text). When the user clicks the row I want that text in that cell to be added to an array.

How Do I grab the text out of the cell?

I already Have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

Is there a simple line I can use to grab the text out the cell that the user clicks?

like image 348
user964627 Avatar asked Sep 11 '25 02:09

user964627


1 Answers

Use UITableView's cellForRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;
}
like image 145
Joe Avatar answered Sep 12 '25 14:09

Joe