gpt4 book ai didi

ios - 从数据库中删除记录

转载 作者:行者123 更新时间:2023-11-29 10:55:39 26 4
gpt4 key购买 nike

我试图从 TableView 中删除单元格并从数据库中删除其关联记录,但均未成功。这是我的代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {

// Delete the row from the data source
[self.arr removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
NSError *error = nil;
[self.context save:&error];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
[self.tableView reloadData];
}

欢迎提出任何建议。我已经尝试了一切,在 SO 上阅读了许多类似的问题,仍然无法弄清楚。谢谢。

最佳答案

在删除数组调用中的对象之前:

NSManagedObject *eventToDelete = [matchedObjects objectAtIndex:indexPath.row];
[context deleteObject:eventToDelete];

关于ios - 从数据库中删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535971/

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