I want to enable an UIAlertView-Request before the user can delete an item from my tableview. But the indexPath seems to be “nil”…
That is my coding:
The header-file looks like that ..
@interface ReturnRootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
// ..
NSIndexPath *deleteSelectedRow;
}
// ..
@property (nonatomic, retain) NSIndexPath *deleteSelectedRow;
@end
.. the implemtation file looks like that ..
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSUserDefaults *setting = [NSUserDefaults standardUserDefaults];
[setting synchronize];
// for the UIAlert-View handling:
deleteSelectedRow = indexPath;
if ([setting boolForKey:@"delete_preference"]) {
// Sicherheitsabfrage vor dem Löschen
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Achtung", @" ")
message:NSLocalizedString(@"Sind Sie sicher, dass Sie den Eintrag löschen wollen?", @" ")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Nein", @"Nein")
otherButtonTitles:NSLocalizedString(@"Ja", @"Ja"), nil];
[alert show];
[alert release];
} else {
// just the case you override the settings
[moc deleteObject:[fetchedResultsController objectAtIndexPath:deleteSelectedRow]];
NSError *error = nil;
if (![moc save:&error]) {
NSLog(@"Ungelöstes Problem %@, %@", error, [error userInfo]);
abort();
}
}
}
}
and last but not least the method for the uialertview-handling:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
// Delete request
[moc deleteObject:[fetchedResultsController objectAtIndexPath:deleteSelectedRow]];
// ..
and that is the place where my app dumps! deleteSelectedRow is nil.
by the way: deleteSelectedRow is not nil in the else-Statement from the tableview:commitEditingStyle-method! I’m fully helpless.
Before iOS 5 it works like that …
Thanks for any hints.
ifeelhorst
As it is now, indexPath could be released by the time the alert view is clicked/returns. Change
to
or (to make a copy of it)
This does not explain why it is nil however, try putting a breakpoint on that line and on the alert view
clickedButtonAtIndexcallback to see what happens.