gpt4 book ai didi

ios - 删除时该行不会在 UITableView 中消失

转载 作者:可可西里 更新时间:2023-11-01 05:53:53 25 4
gpt4 key购买 nike

我正在使用数据库中的文件名填充我的 iOS TableView 。一切都按预期显示在 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];
}
}

最佳答案

您实际上是将之前删除的值传递给 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];
}

试试这个。

关于ios - 删除时该行不会在 UITableView 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24749931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com