Sqlite数据库并滑动删除

发布于 2024-10-11 09:44:04 字数 1161 浏览 6 评论 0原文

我正在从事的项目要求我使用 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        
    }
}

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

The project I'm working on required me to use a sqlite database, and I've been trying to get swipe to delete to work on my 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"];

That's the code to get rid of something from my database. When I try to apply this to my swipe to delete command of:

-

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

      //code goes here        
    }
}

It just doesn't want to work, what am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-10-18 09:44:04

在您的 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”替换为您所说的表!)

In your tableView Data Source, try implementing this:

(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];        
    }
}

(replace "theTable" with whatever you've called your table!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文