Search code examples
iphoneuiactionsheetobjective-c-category

UIActionSheet, get the clickedButtonIndex before proceeding?


What I want to do is on a UITableView, the user swipes a row to bring up the option to delete, once they press delete, then a UIActionSheet pops up to make sure they want to delete the row since it's more important than a typical row in a table. Depending on what they press, then I can delete the data in that row from the database. How do I get the indexPath for that row into the UIActionSheet though? If I had a one section table, then I might be able to use the tag for that row and recreate the indexPath, but with multiple sections, how can this be done?

It seems like there could be a better way by having a categoroy or something so in my

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

method, I can just delete the row in there. Or is there a way to pass back the information from the UIActionSheet? Thanks!


Solution

  • In -tableView:commitEditingStyle:forRowAtIndexPath: you can store the indexPath as a property/ivar and then present the ActionSheet.

    When the user confirms the deletion, just remove the data (you've stored the indexPath!) and remove the cell from tableview (-deleteRowsAtIndexPaths:withRowAnimation: or -reloadData). Don't forget to retain/release the indexPath.