-(void) deletedata:(id) sender
{
if(deleteStmt == nil)
{
const char *sql = "delete from cosmicnumber where name='%@' ";
if(sqlite3_prepare_v2(db2, sql, -1, &deleteStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(db2));
NSLog(@"%@",strNam);
}
//When binding parameters, index starts from 1 and not zero.
sqlite3_bind_text(deleteStmt, 1, [strNam UTF8String], -1, SQLITE_TRANSIENT);
if (SQLITE_DONE != sqlite3_step(deleteStmt))
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(db2));
sqlite3_reset(deleteStmt);
}
1
A
回答
0
你在這裏用什麼來連接sqlite? 即,如果你使用coredata,那麼它的代碼很容易與小邏輯你使用什麼?
像...
-(void) deleteAllData {
NSManagedObjectContext *moc = appDelegate.managedObjectContext;///your data which store in coredata
//---------------Fetching and Deleting Category---------
NSFetchRequest *fetchRequest;
NSEntityDescription *entity;
NSArray *arrobjects;
NSError *error;
//---------------Fetching and Deleting ITems---------
fetchRequest = [[NSFetchRequest alloc] init];
entity = [NSEntityDescription entityForName:@"yourEntity" inManagedObjectContext:moc]; ///use your entity name..
[fetchRequest setEntity:entity];
arrobjects = [moc executeFetchRequest:fetchRequest error:nil];//arrobjects is array which stor youe another array or record which you want to delete
for (NSManagedObject *managedObject in arrobjects) {
[moc deleteObject:managedObject];
}
error = nil;
[moc save:&error];
}
後reloadData
方法
[yourTable reloadData];
希望,這幫助你.. :)
1
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
sqlite3_stmt *stmt;
if (sqlite3_open([[objdelegate getDBPath] UTF8String], &dbtest) == SQLITE_OK){
NSString *deleteSQL =[NSString stringWithFormat:@"DELETE from test where test_Id=\"%@\"",[objdelegate.listOfTestId objectAtIndex:indexPath.row]];
NSLog(@"Query : %@",deleteSQL);
const char *delete_stmt=[deleteSQL UTF8String];
sqlite3_prepare_v2(dbtest, delete_stmt, -1, &stmt, NULL);
if(sqlite3_step(stmt) == SQLITE_DONE)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete" message:@"Record Deleted..!!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete" message:@"Record Not Deleted..!!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
[self getdata]; // Here Call your main getdata function from where you are fetching your data from database
[tableView reloadData];
}
0
或許,這種意志重載表幫你。其中_allDownloadedSongs是從中填充表的數組,deleteRowFromDatabase是從數組,數據庫和talbeView中刪除特定行的方法。
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *strQuery;
NSString *deleteRow;
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[tblView beginUpdates];
NSMutableDictionary *dic = (NSMutableDictionary *)[_allDownloadedSongs objectAtIndex:indexPath.row];
deleteRow = [dic valueForKey:@"Id"];
[self deleteRowFromDatabase:deleteRow];
[_allDownloadedSongs removeObjectAtIndex:indexPath.row];
[tblView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
[tblView endUpdates];
}
}
//和數據庫中刪除
- (void)deleteRowFromDatabase:(NSString *)deleteRow
{
AppDelegate *obj = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *strQuery = [NSString stringWithFormat:@"DELETE FROM DownloadedSongs WHERE Id=%d", rowId];
[obj InsUpdateDelData:strQuery];
}
相關問題
- 1. 從數據源中刪除表格視圖行數據
- 2. 如何在列表視圖中從sqlite中刪除行Android
- 3. 從表格視圖中刪除一行
- 4. 從表格視圖中刪除一行
- 5. 從表格視圖中刪除行
- 6. 如何從表格視圖中刪除特定數據
- 7. 刪除從表視圖,並記錄行從SQLite數據庫
- 8. 如何從iPhone中的SQLite數據庫中刪除表格數據
- 9. 如何從Sqlite數據庫中刪除與列表視圖相關的項目
- 10. 如何從核心數據和表視圖中刪除行
- 11. 如何在Swift 2.0中從sqlite數據庫中輕掃和刪除選定的表視圖行數據?
- 12. 從列表視圖中刪除數據
- 13. 如何從sqlite中的多個表中刪除數據?
- 14. 如何從sqlite中刪除數據
- 15. Android的sqlite從列表視圖刪除
- 16. 如何刪除/從數據視圖中刪除行/列(不使用數據視圖刪除。)
- 17. 從sqlite表中刪除數據iphone sdk?
- 18. 如何從表格中的api刪除表格tr數據?
- 19. 從表和sqlite數據庫刪除行
- 20. 從表和sqlite數據庫刪除行
- 21. 如何從SQLite數據庫中刪除特定的行
- 22. 從SQLite的表中刪除
- 23. 在表格視圖中刪除行
- 24. 如何刪除sqlite數據庫表中的一行?
- 25. 如何從按鈕單擊的表格視圖中刪除數據?
- 26. 從列表視圖中刪除一個項目(使用sqlite)導致只從listview中刪除它。不能從數據庫中刪除它
- 27. 如何從網格視圖中刪除項目從下拉列表中刪除
- 28. xcode - 從表格視圖刪除一行
- 29. 如何刪除從網格視圖一個視圖中的Android
- 30. 如何從表視圖行和核心數據實體中刪除數據?
試試這個代碼..希望這將解決您的問題.. –
感謝名單科莫爾,它的工作,但不是在 - (空)的tableView:(UITableView的* )tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath。它在按鈕上的工作,我採取了行,但問題時刪除最後一排,當我選擇第一行。 – garry
如果此代碼工作,然後upvote我的答案。我認爲你沒有獲取你當前的指數值。您需要獲取當前的索引,然後在上面的代碼中傳遞該索引。 –