나는 여전히 당신의 도움이 필요합니다.
작동하지 않으려는 코드 조각이 있습니다.테이블 및 sqlite 데이터베이스에서 행 삭제
-(void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSDictionary *rowVals = (NSDictionary *) [shoppingListItems objectAtIndex:indexPath.row];
NSString *keyValue = (NSString *) [rowVals objectForKey:@"key"];
[tableView beginUpdates];
sqlite3 *db;
int dbrc; //Codice di ritorno del database (database return code)
DatabaseShoppingListAppDelegate *appDelegate = (DatabaseShoppingListAppDelegate*) [UIApplication sharedApplication].delegate;
const char *dbFilePathUTF8 = [appDelegate.dbFilePath UTF8String];
dbrc = sqlite3_open(dbFilePathUTF8, &db);
if (dbrc) {
NSLog(@"Impossibile aprire il Database!");
return;
}
sqlite3_stmt *dbps; //Istruzione di preparazione del database
NSString *deleteStatementsNS = [NSString stringWithFormat: @"DELETE FROM \"shoppinglist\" WHERE key='%@'", keyValue];
const char *deleteStatement = [deleteStatementsNS UTF8String];
dbrc = sqlite3_prepare_v2(db, deleteStatement, -1, &dbps, NULL);
dbrc = sqlite3_step(dbps);
//faccio pulizia rilasciando i database
sqlite3_finalize(dbps);
sqlite3_close(db);
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[shoppingListItems removeObjectAtIndex:indexPath.row];
[tableView reloadData];
[tableView endUpdates];
}
}
사실, 제대로 작동합니다. 테이블의 행을 스 와이프하여 삭제하고, 페이드 효과가 적용되고, 콘텐츠가 데이터베이스와 테이블에서 삭제됩니다.
하지만 난 그냥 첫 번째 이후에 다른 요소를 제거하려고하면 내가 다른 탭으로 이동하면 다시 가서 행을 제거
[shoppingListItems removeObjectAtIndex:indexPath.row];
에 SIGABRT을 가지고, 모든 작동합니다 ...
모든 아이디어? 당신은 교환 할 수 있습니다
나도 몰라 ..... 이런 식으로 TRY ... 그리고 마지막 행에 문제도있다 ... – Oiproks