2011-01-09 87 views
0

我的工作要求我使用SQLite數據庫的項目,我一直在試圖讓滑動刪除在我的tableView工作:SQLite數據庫和滑動刪除

[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   
    } 
} 

它只是不想工作,我做錯了什麼?

+0

我有但不是在這種風格:「的tableView :commitEditingStyle:forRowAtIndexPath:「我用過」 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath「等,但我還沒有最後一個,如何我應該執行它們嗎? – 2011-01-09 13:40:29

回答

2

在你的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」不管你已經叫你的表!)