2013-03-18 143 views
0

你能發現任何會導致它不起作用的東西嗎?刪除SQLITE行UITABLEVIEW

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

if (editingStyle == UITableViewCellEditingStyleDelete) { 
    int record_to_delete = [[[data objectAtIndex:indexPath.row] recordID] integerValue]; 
    [data removeObjectAtIndex:indexPath.row]; 
    [self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:YES]; 
    //Delete from TABLENAME where CRITERIA1=VALUE1 (AND CRITERIA2=VALUE2...) 
    //Delete from Data where RecordID=xxx 

    sqlite3 *database; 
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { 
     NSString *sqlStatement = [NSString stringWithFormat:@"delete from Data where RecordID = %d",record_to_delete]; 
     NSLog(@"Statement is: %@", sqlStatement); 
     sqlite3_stmt *compiledStatement; 
     NSLog(@"Statement"); 
     if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK){ 
     } 
     NSLog(@"Deleting"); 
     sqlite3_finalize(compiledStatement); 
     NSLog(@"Deleted"); 
    } 
    sqlite3_close(database); 

} 
} 

SQL語句在我的數據庫軟件中執行時工作正常。但是,在iPhone模擬器上運行時,它不會從數據庫中刪除它。任何幫助將不勝感激。對不起,我不能更具體。

感謝

2013-03-18 18:45:07.211 Navigation[842:c07] Statement is: delete from Data where RecordID = 1 
2013-03-18 18:45:07.212 Navigation[842:c07] Statement 
2013-03-18 18:45:07.212 Navigation[842:c07] Deleting 
2013-03-18 18:45:07.213 Navigation[842:c07] Deleted 

UPDATE:設法得到它的工作。我只是想念。

sqlite3_step(compiledStatement) 

無論如何,謝謝。

+0

打開數據庫?你能否把你的問題和日誌一起包括在內? – 2013-03-18 18:41:21

+1

xcode刪除設備上的數據庫對我來說是新消息。 – 2013-03-18 18:41:23

回答

1

在iOS中,您不具有應用程序包的寫入權限。建議的方法是在第一次運行應用程序時將數據庫複製到文檔文件夾中,然後從那裏管理數據庫。

看這裏:Unable to connect SQLite Database in iOS

+0

我將如何將它複製到文檔文件夾中? – 2013-03-18 18:47:29

+0

我添加了一個有用問題的鏈接。 – 2013-03-18 19:00:19

+0

我很確定我的數據庫已經打開。因爲所有內容都是從數據庫中顯示的。這只是刪除部分,似乎沒有工作。 – 2013-03-18 19:09:31