user964627 user964627 - 3 months ago 7
iOS Question

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?

Joe Joe
Answer

Use UITableView's cellForRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;
}
Comments