I have a delete button inside a UITableView cell. The function of this button is to delete the content of that specific cell out of Core Data. This process cannot be undone; so, I added UIAlertView to let users confirm their decision before proceeding into deletion.
It seems that I need to code all the deletion logic inside…
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
However, this is a delegate method. The Indexpath of the table cell is missing? How do I access the UITableViewCell data after the UIAlertView button is clicked?
One of the idea I have in mind now is to traverse up using alertview.superview until I find UITableViewCell, and access its indexPath property. But this does not seem to be elegant. Should there should be another way to fix this issue?
Because the
UIAlertViewis modal I don’t see any problems in saving the indexPath of theUITableViewCellbefore presenting theUIAlertViewin a (global) variable (and maybe clearing that variable in- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex(just to be on the safe side).At least this is what I did when I had this issue.
ps. It’s far from best practice but as long as you do some basic checks you should be ok.