iPhone: Crash When Deleting UITableView Rows

Posted by Ajeet Kumar Yadav on Stack Overflow See other posts from Stack Overflow or by Ajeet Kumar Yadav
Published on 2010-04-06T10:54:05Z Indexed on 2010/04/06 11:53 UTC
Read the original article Hit count: 282

Hi,

I am new in iPhone development. I am developing an application that fetches a value from a database and displays it in a table view. I want to delete table rows one by one but the rows do not delete and the application crashes.

Here is my row deletion code:

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
                                     forRowAtIndexPath:(NSIndexPath *)indexPath 
{    
if(editingStyle == UITableViewCellEditingStyleDelete) {
    SanjeevKapoorAppDelegate *appDelegate =(SanjeevKapoorAppDelegate *)[[UIApplication sharedApplication] delegate];
    list *animal =[appDelegate.list1 objectAtIndex:indexPath.row];
    [appDelegate deleteCoffee];      
    [self.tableView reloadData];
    //Delete the object from the table.
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

I also delete all rows with this action:

-(IBAction)deletebtn:(id)sender{
    SanjeevKapoorAppDelegate *appDelegate =(SanjeevKapoorAppDelegate *)[[UIApplication sharedApplication] delegate];
       [appDelegate deleteCoffee]; 
       [self.tableView reloadData];
}

How do I properly implement delete in an UITableView?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c