2011-02-04 24 views
0

任何人都可以幫助我如何使用fmdb從uitableviewcell中的數據庫刪除行。我如何刪除使用fmdb在uitableviewcell中的數據庫中的行

我的意思是我寫了關於刪除datamanager.m中的查詢 - (void)deleteTodo;它正在工作並在控制檯中顯示爲已刪除該行。但我想刪除iPhone模擬器中的行,當我按下編輯按鈕。

如何在Datamanger.m類中調用 - (void)deleteTodo。

我的代碼.......

-(void) deleteTodo 
{ 
    [dataBase executeUpdate:@" delete from todo where pk='8'"]; 
    NSLog(@"Deleted"); 

} 

但我怎麼能在commitEditingStyle方法使用它rootviewcontroller.m。刪除行。

請幫我....

+0

您可能需要使你的代碼很好地編輯您的帖子。只需在代碼前添加4個空格,它就會以代碼佈局顯示出來。 – 2011-02-04 16:24:13

回答

0

你應該代碼如下所示,

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
      forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     // If row is deleted, remove it from the list. 
     if (editingStyle == UITableViewCellEditingStyleDelete) 
     { 
      [dataSource removeDataAtIndex:indexPath.row]; 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
        withRowAnimation:UITableViewRowAnimationFade]; 
      // Create obj for the class DAtamanager 
      DataManager *obj= [[DataManager alloc] init]; 
      [obj deleteTodo]; 
      [obj release]; 
     } 

    } 
+0

謝謝KingofBliss – 2011-02-06 14:09:16

相關問題