简体   繁体   English

如何使用fmdb从uitableviewcell中的数据库中删除行

[英]How can i delete row from database in uitableviewcell using fmdb

Can anyone help me how to delete row from database in uitableviewcell using fmdb. 谁能帮助我如何使用fmdb从uitableviewcell中的数据库中删除行。

I mean i wrote query about delete in datamanager.m as -(void) deleteTodo; 我的意思是我在datamanager.m中以-(void)deleteTodo编写了有关delete的查询; it's working and shown in console as deleted the row. 它正在工作,并在控制台中显示为已删除的行。 But i wanna delete row in iphone simulator when i press Edit button. 但是,当我按下“编辑”按钮时,我想在iPhone模拟器中删除行。

How can i call that -(void) deleteTodo in Datamanger.m class. 我如何在Datamanger.m类中将其称为-(void)deleteTodo。

My code is....... 我的代码是....

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

}

But how can i use it in rootviewcontroller.m at commitEditingStyle Method. 但是我如何在commitEditingStyle方法的rootviewcontroller.m中使用它。 to delete row. 删除行。

Please Help me.... 请帮我....

Than

You should code as follows, 您应该编写如下代码,

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

   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM