这就是我在标题中所做的
static sqlite3 *database = nil;
static sqlite3_stmt *deleteStmt = nil;
@implementation SQLAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize coffeeArray;
这就是我用来删除原始的
- (void) removeCoffee:(NSNumber *)coffeeObj {
NSLog(@"coffeeObj%@",coffeeObj);
int myInteger = [coffeeObj integerValue];
NSLog(@"myInteger%d",myInteger);
// print this myInteger0
NSLog(@"%@",coffeeArray);
//print object
if (sqlite3_open([self getDBPath], &database) == SQLITE_OK)
{
NSLog(@"myInteger%@",[self getDBPath]);
NSString *sql = [NSString stringWithFormat: @"delete from Coffee where CoffeeID =%d",myInteger];
const char *del_stmt = [sql UTF8String];
NSLog(@"%@",del_stmt); // getting print
// print this delete from Coffee where CoffeeID =0.
sqlite3_prepare_v2(database, del_stmt, -1, & deleteStmt, NULL);
NSLog(@"sqlite3_step(deleteStmt) == SQLITE_DONE%@",sqlite3_step(deleteStmt) == SQLITE_DONE);
// this print null
if (sqlite3_step(deleteStmt) == SQLITE_DONE)
{
//NSLog(@"hi") this is not getting print
} else {
//NSLog(@"hi") this is getting print
}
sqlite3_finalize(deleteStmt);
sqlite3_close(database);
[coffeeArray removeObjectAtIndex:myInteger];
NSLog(@"%@",coffeeArray);
// object is deleted
}
}
我的桌子如下
table name = Coffee
CoffeeID(INTEGER)=0
CoffeeName(VARCHAR)=Latte
Price(REAL)=2.99
事情运行完美的地方从数组中删除了对象,这就是为什么它没有出现在表格单元格上。但它没有从数据库表中删除,这就是为什么当我再次启动应用程序然后它再次显示时请帮助我做错了什么。