2011-06-23 152 views
0

我是iPhone编程的新手,对数据库不太了解。我正在制作一个iphone应用程序,在这个应用程序中,我使用数据库来存储联系人,每当我添加新的联系人时,就会将其添加到其他联系人正在显示的表格视图中。但我希望如果我不需要任何联系,那么通过单击表视图的行,它必须从tableview和数据库中删除。我该怎么做。请帮帮我。从数据库中删除数据

非常感谢。

+2

您需要提供一些细节的数据库使用的是怎么样,如sqlite,CoreData,plist等... –

+0

我正在使用sqlite。 –

回答

1

您可以使用此代码

- (void)viewDidLoad { 

self.navigationItem.rightBarButtonItem = self.editButtonItem; 

} 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     ; 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; 
    } 

     }