UITableView DidSelectRowAtIndexPath?

Use UITableView's cellForRowAtIndexPath:

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

My first guess would be getting the index, [indexPath row]; then fetching the data from your datasource ( an array or core data ) rather than directly from the table itself.


It's the inverse of what you did in cellForRowAtIndexPath.

 [myArray addObject: [datasource objectAtIndex:indexPath.row]];

In general, you can find most answers to questions like this in the Apple documentation. For this case, look under UITableView Class Reference and you will see a section header: Accessing Cells and Sections. This give you the following method:

– cellForRowAtIndexPath:

Now use this to access the cell, and then use get the text from the cell (if you're unsure how, look under the UITableViewCell Class Reference.

All together, your method might look something like this:

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