gpt4 book ai didi

ios - Sqlite数据库,滑动删除

转载 作者:行者123 更新时间:2023-11-28 23:18:20 25 4
gpt4 key购买 nike

我正在从事的项目要求我使用 sqlite 数据库,并且我一直在尝试滑动删除以在我的 tableView 上工作:

[self performSelectorOnMainThread:@selector(removeMovieFromCache:) withObject:[NSNumber numberWithInt:movieId] waitUntilDone:YES];
[db performSelectorOnMainThread:@selector(performQuery:) withObject:[NSString stringWithFormat:@"DELETE FROM movie WHERE id = %d", movieId] waitUntilDone:YES];
[db performSelectorOnMainThread:@selector(performQuery:) withObject:[NSString stringWithFormat:@"DELETE FROM new_movies WHERE new_movie_id = %d", movieId] waitUntilDone:YES];
[self removeMovieFromCache:movieId];
[db performQueryWithFormat:@"DELETE FROM movie WHERE id = %d", movieId];
[db performQueryWithFormat:@"DELETE FROM new_movies WHERE new_movie_id = %d", movieId];
[db performQuery:@"COMMIT"];

这是从我的数据库中删除某些内容的代码。当我尝试将此应用到我的滑动删除命令时:

-

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

//code goes here
}
}

它只是不想工作,我做错了什么?

最佳答案

在你的 tableView 数据源中,尝试实现这个:

(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath 
{
return UITableViewCellEditingStyleDelete;
}


(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}

(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)movieID
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// First delete the row from the table, then delete from the DB, finally reload the date in the table
[theTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
// code to delete from DB
[theTable reloadData];
}
}

(将“theTable”替换为您对表格的命名!)

关于ios - Sqlite数据库,滑动删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4639333/

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