The row doesn't fade away in UITableView when deleting - ios

I am populating my iOS table view with the names of files inside my database. Everything is displayed in the tableView as expected. The problem comes when i delete it, it deleted the entries in the database but the entry doesn't fade away in the UITableView. Here is my code:
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
DBHandler *handler;
[handler ResumeID:[mydataList objectAtIndex:indexPath.row]]; //mydataList contains the array that contains name of all the entries in the DB and is displaying them on the tableview.
[mydataList removeObjectAtIndex:indexPath.row];
NSLog(#"%ld",indexPath.row);
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}

You are actually passing the value which is deleted before, to the DBHandler. Check the code,
if (editingStyle == UITableViewCellEditingStyleDelete)
{
DBHandler *handler ;
[handler ResumeID:[mydataList objectAtIndex:indexPath.row]]; // Pass the object from the dataSource before deleting the object from the dataSource.
[mydataList removeObjectAtIndex:indexPath.row]; // Remove object after passing it to the DBHandler
NSLog(#"%ld",indexPath.row);
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Try this.

Its a bug of ios7.. the tablerow animations are broken! My fix was to fadeOut the cell right before the tableViewRowAnimation..
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// hide cell, because animations are broken on ios7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
}
[tableView deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationMiddle];
}

after deleting refresh the view
[tableView reloadData];

Related

Delete button remains displayed when using commitEditingStyle (cf gif)

I'm trying to delete a UITableviewCell with a swipe gesture.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
With
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_commentsData removeObjectAtIndex:indexPath.row];
_NBComment--;
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
The result is this:
The delete buttons remains displayed after the row deletion.
Do you have an idea to make the row deletion smoother?
Thanks in advance
Don't ask me why, but this code works:
[_commentsData removeObjectAtIndex:indexPath.row];
_NBComment--;
[tableView beginUpdates];
[tableView setEditing:NO animated:NO];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
You can try adding this code after deletion:
[tableview reloadData];

UITableView cell not deleting

Basically I have an app where you can swipe a tablecell off the screen and it "deletes" the cell. My delete method is called by this: (this happens when the cell reaches a certain point on the phone)
[tableCellTrash addObject: [NSIndexPath indexPathForRow:[numbers indexOfObject:[aPanGestureRecognizer view]] inSection:0]];
UITableViewCell *cell = [numbers objectAtIndex:[numbers indexOfObject:[aPanGestureRecognizer view]]];
[self deleteCell: cell];
This is the delete cell method
-(void)deleteCell: (UITableViewCell *) cell{
[self.tableView beginUpdates];
[numbers removeObject:cell];
[self.tableView deleteRowsAtIndexPaths:tableCellTrash withRowAnimation:UITableViewRowAnimationFade];
[tableCellTrash removeObjectAtIndex:0];
[self.tableView endUpdates];
//[self.tableView reloadData];
}
I have no idea what's wrong, the cell doesn't delete. Any help would be appreciated.
tableviews have a delegate method to handle the event for delete:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[tableView reloadData];
}

UITableView cells delete ingloriously

I've been reading a lot about updating a UITableView after you remove rows by both IndexPath and the datasource, which it seems like comes down to [tableView startUpdates], run whatever update code you have, then [tableView endUpdates].
Despite following numerous examples to a T, and utilizing [tableView deleteRowsAtIndexPaths:<indexPaths> withRowAnimation:UITableViewRowAnimationTop];
, I can't seem to make my rows delete in any way but what the following depicts:
http://www.youtube.com/watch?v=l6ov1FR0R4g&feature=youtu.be (essentially, if there are n > 1 rows, the row will simply blink out, and if there is n = 1 row, it will slide outward, stop, then disappear).
I'd really like a smoother behavior, like, perhaps, the row slides out, as the row slides up. Here's the code executing the deletion:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
int idx = [indexPath indexAtPosition:1];
LoLoanedItemDoc *itemDoc = [[self items] objectAtIndex:idx];
// Delete notification
[[UIApplication sharedApplication] cancelLocalNotification:[[itemDoc data] notification]];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationTop];
// Remove from datasource
[[self items] removeObject:itemDoc];
[tableView endUpdates];
// Delete folder
[itemDoc deleteDoc];
}
I've done it two ways, both of which work for me.
Delete the item before you perform the updates.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Delete the item from the data source
[self removeProductFromQuoteAtIndexPath:indexPath];
//Do the updates
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[shipping removeObjectAtIndex:indexPath.row - 1];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Are you performing any type of operation on the cell before it deletes? (like closing the drawer animation you have).

tableview internal inconsistency when deleting

I have an array (datasource) with a set of addresses, my tableview is set to have double the amount of cells from the datasource so I can style the odd cells to be small and clear (to make the tableview look like the cells are separated by a small space). My problem comes when deleting a row, I do the following:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView beginUpdates];
if (editingStyle==UITableViewCellEditingStyleDelete) {
[self DeleteAddress:[ListAddress objectAtIndex:indexPath.row/2]];
[ListAddress removeObjectAtIndex: indexPath.row/2];
NSIndexPath *nextIndexPath = [[NSIndexPath alloc] initWithIndex:indexPath.row+1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nextIndexPath,nil] withRowAnimation:UITableViewRowAnimationRight];
}else if (editingStyle == UITableViewCellEditingStyleInsert){
[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
[tableView endUpdates];
}
The DeleteAddress method deletes the address from the database.
When the debugger reaches the [tableview endUpdate] function a get the following error:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070
NSInternalInconsistencyException
Just follow the sample code.Delete one row from your data source.Hope its useful for you.This code works for my app.Try it
// Swipe to delete has been used. Remove the table item
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Get a reference to the table item in our data array
Pictures *itemToDelete = [self.pictureListData objectAtIndex:indexPath.row];
// Delete the item in Core Data
[self.managedObjectContext deleteObject:itemToDelete];
// Remove the item from our array
[pictureListData removeObjectAtIndex:indexPath.row];
// Commit the deletion in core data
NSError *error;
if (![self.managedObjectContext save:&error])
NSLog(#"Failed to delete picture item with error: %#", [error domain]);
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
My problem was that I was creating my nextIndexPath variable the wrong way. It should have been like this:
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
Also I couldn't delete both rows at the same time, I needed to delete them separately from bottom:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:nextIndexPath] withRowAnimation:UITableViewRowAnimationRight];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

Xcode - TableView -> delete row - localNotification

My problem is that my delete method do not delete the right row!
In this tableView the user can save localNotifications for a special date. So if I create more than one localNot, the delete method does not delete the selected row! It deletes the last entry only ...
26.02.2012 delete third
27.02.2012 delete second
etc... delete first
Whats wrong?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(tableView.editing && editingStyle== UITableViewCellEditingStyleDelete)
{
[tableView beginUpdates];
[[UIApplication sharedApplication] cancelLocalNotification:notification];
[notificationsArray removeObjectAtIndex:indexPath.row];
NSLog(#"%#", notification);
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
[tableView reloadData];
}
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
// UITableViewCellEditingStyleNone;
return YES;
}

Resources