您好我正在使用sqlite,並且我已經成功地將數據添加到數據庫中,但問題是,當我刪除某些其他表視圖中的一些數據並導航回到我的主視圖和我按UIBarButton調用一個函數,再次檢查數據庫中的數據。從sqlite中獲取數據的問題
現在我的問題是,在表中新顯示的數據是被刪除的數據,所以我試圖打印我的可變數組,並在日誌中我看到他們是沒有這樣的數據,但在表中也是如此查看單元格我看到的數據。下面給出的是我的代碼在db
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *databasePath = [documentsDir stringByAppendingPathComponent:@"PotsDB.sqlite"]; sqlite3 *database; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { // Setup the SQL Statement and compile it for faster access const char *sqlStatement = "SELECT potsName FROM potsDetail;"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *Potname=[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 0)]; NSString * pname = [[NSString alloc]initWithFormat:@"%@",Potname]; [potsArray addObject:pname]; NSLog(@"The data in the array is %@",potsArray); } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(database);
而且繼承人的代碼,我上刷新按鈕
-(IBAction)RefreshButtonTouched { [potsArray removeAllObjects]; [self Read_Potname_FromDB]; [potsTableView reloadData]; }
刪除查詢中,我正在寫打電話來讀取數據,我想我是在這裏刪除一些錯誤
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *databasePath = [documentsDir stringByAppendingPathComponent:@"PotsDB.sqlite"]; sqlite3 *database; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { // Setup the SQL Statement and compile it for faster access NSString *deleteStatement = [NSString stringWithFormat:@"delete from potsDetail where potsName = '%@'",sptr]; const char *sqlStatement = [deleteStatement cStringUsingEncoding:NSASCIIStringEncoding]; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *Potname=[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 0)]; NSString * pname = [[NSString alloc]initWithFormat:@"%@",Potname]; [potsArray addObject:pname]; //[pname release]; } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(database);
請幫我解決這個問題。在此先感謝
是的我試過了,你可以在上面的代碼中看到我已經調用了sqlite3_finalize(compiledStatement); – Radix
現在,有可能的UITableViewCell,你在(cell == nil)範圍內設置標籤文本嗎?我認爲,問題是在tableview上顯示標籤 – iMOBDEV
是的,我只是這樣做的 – Radix