i have one section table which contain the section and i want to delete the perticular cell swap and delete this cell and remove that cell from table and also remove from the array.
and how to animate that when the delete the cell.
for that i code below but which is not working please help to do this.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.reports removeObjectAtIndex:indexPath.row];
[tbl reloadData];
[tbl deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
After much more R&D then i build up new code and which is successfully Run
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[[[self.reports objectAtIndex:indexPath.section] valueForKey:@"events"] removeObjectAtIndex:indexPath.row];
[tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationLeft];
[NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(tableReload) userInfo: nil repeats: NO];
}
}
-(void)tableReload{
[tbl reloadData]; }
Firstly you should not
Reload tablebefore deleting row from table. Secondly, in your case you have multiple sections and multiple rows in that section, I guess. So, yourwon’t work.
Deleting object from array will work. You don’t have to delete row from your table. Just reload table :
But do take care that you are putting the correct indexNumber.