user964627 user964627 - 1 year ago 110
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 Source

Use UITableView's cellForRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download