I'm trying to show a UIAlertView
before actually deleting a cell from a UITableView
NSIndexPath *_tmpIndexPath;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
_tmpIndexPath = indexPath;
NSLog(@"%d", indexPath.row); // 2
NSLog(@"%d", _tmpIndexPath.row); // 2
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Dete" message:@"Are you sure you want to delete this entry?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil] autorelease];
[alert show];
}
}
So both my logs return the correct path.
I have my view delegating the UIAlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%d", _tmpIndexPath.row);
if(buttonIndex == 1)
{
NSLog(@"%d", _tmpIndexPath.row);
}
}
Now I can't figure out why in the clickButtonAtIndex()
I'm getting an error when trying to log _tmpIndexPath.row
*** -[NSIndexPath row]: message sent to deallocated instance 0x12228e00
you will need to retain the indexPath, what is happening is that your indexPath when the alert is dismissed is already deallocated from your system,
Like this
Change
_tmpIndexPath = indexPath;
to
_tmpIndexPath = [indexPath retain];
You can try to do this
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Dete" message:@"Are you sure you want to delete this entry?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil] autorelease];
[alert setTag:indexPath.row];
[alert show];
So you can get the value as
[alertView tag]
In clickedButtonAtIndex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With