0

The Situation

I'd like to be able to get information about the title of a cell within a UITableView when the user swipes the cell (to display the "delete" button).

The Code

When the user swipes a cell in the UITableView, this method is fired:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath

The Problem

I need to be able to get the name of the cell the user "swiped" so that my iOS (Obj-C) app can do various operations, etc.

Everything Else

I know that the indexPath has something, but I can't get an NSString from it (which is what I need).

I was also thinking that a workaround such as using a gesture recognizer instead of the above method might be able to provide me with more information about the cell.

Any ideas as to how I can get the name of the cell when the user "swipes to edit / delete"?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
  • In one place you use "title" and in another "name" of the cell, what do you mean by these? Do you have a label in the cell that displays a title? – rdelmar May 31 '12 at 20:19
  • @rdelmar Sorry, no I need the text in the cell. Would that be the title or name? – Sam Spencer May 31 '12 at 20:27

2 Answers2

2
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *text = cell.textLabel.text;

    // do something with text
}
sc0rp10n
  • 1,118
  • 7
  • 8
0

Please, how does your table work in the first place - you don't seem to understand the basic principles of it. You back your table up with a data model. YOU provide and construct the cells for each indexPath, so you should know how to access the data in your model using that swiped indexPath, no? Of course you could also ask the tableView delegate (yourself) for the swiped cell by calling tableView:cellForRowAtIndexPath: and then check the labels on that cell.

Have a look at the implementation of your tabkeView:cellForRowAtIndexPath: method all your info of how to get the data should be there...

All in all it's pretty easy, if you provide some code you sure will get more hints.

Mario
  • 4,530
  • 1
  • 21
  • 32