我用我的数据库中的文件名填充我的iOS表视图。所有内容都按预期显示在tableView中。当我删除它时,问题就出现了,它删除了数据库中的条目,但条目在UITableView
中没有消失。这是我的代码:
- (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];
}
}
答案 0 :(得分:3)
您实际上是将之前删除的值传递给DBHandler
。检查代码,
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];
}
试试这个。
答案 1 :(得分:0)
它是ios7的一个bug ..桌面动画被破坏了!我的修复是在tableViewRowAnimation ..
之前fadeOut单元格- (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];
}
答案 2 :(得分:-1)
删除后刷新视图 [tableView reloadData];