sqlite .data からデータを削除しようとしています。下から上に削除しますが、データをランダムに削除すると、データが 1 つの行の詳細から別の行にスワイプされました。データを削除するのを手伝ってください。
これは私のコードです
appdelegate.m
-(void)deleteData:(NSString *)str:(NSString *)string
{
NSLog(@"intIndexpath:--> %d",intIndexpath);
[self createEditableCopyOfDatabaseIfNeeded];
sqlite3_stmt *deleteStatement = nil;
NSString *sql;
int returnvalue;
sql = [NSString stringWithFormat:@"DELETE FROM UserInfo_1 WHERE rowid=%d",intIndexpath+1];
returnvalue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &deleteStatement, NULL);
if (returnvalue == 1)
{
NSAssert1 (0,@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_text(deleteStatement, 1,[strAcountName UTF8String], -1, SQLITE_TRANSIENT);
if (SQLITE_DONE!= sqlite3_step(deleteStatement))
{
NSAssert1(0, @"Error while deleteing data. '%s'", sqlite3_errmsg(database));
}
if (sqlite3_prepare(database, [sql UTF8String], -1, &deleteStatement, NULL) == SQLITE_OK)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete" message:@"Record Deleted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
else
sqlite3_reset(deleteStatement);
sqlite3_finalize(deleteStatement);
deleteStatement = NULL;
}
tableview.m
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
apd.intIndexpath = indexPath.row;
[apd deleteData:[apd.ArrAcName objectAtIndex:indexPath.row] :apd.strAcountName];
[apd.ArrAcName removeObjectAtIndex:indexPath.row];
apd =(PasswordAppDelegate *)[[UIApplication sharedApplication]delegate];
// NSLog(@"apd.strAcountName is:--> %@",apd.strAcountName);
// [apd deleteData:apd.strAcountName];
self.navigationItem.title =@"Details";
[tableView reloadData];
}
}