Search code examples
objective-ciosuitableviewuiswipegesturerecognizer

Getting name of cell from indexPath / Swip Gesture


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"?


Solution

  • - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        NSString *text = cell.textLabel.text;
    
        // do something with text
    }