下面是我用來填充UITableView與sqlite數據庫中的列的內容的方法的代碼。但是,這在運行時沒有提供任何錯誤,但仍然不會在UITableView中提供任何數據。如果有人可以幫助,它將不勝感激。UITableView沒有得到填充sqlite數據庫列
- (void)viewDidLoad{
[super viewDidLoad];
self.title = @"Strings List";
UITableViewCell *cell;
NSString *docsDir;
NSArray *dirPaths;
sqlite3_stmt *statement;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc]initWithString: [docsDir stringByAppendingPathComponent:@"strings.sqlite"]];
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: databasePath ] == NO)
{
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString * query =
@"SELECT string FROM strings";
const char * stmt = [query UTF8String];
if (sqlite3_prepare_v2(contactDB, stmt, -1,&statement, NULL)==SQLITE_OK){
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *string = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(statement, 0)];
cell.textLabel.text = string; }
}
else NSLog(@"Failed");
sqlite3_finalize(statement);
}
sqlite3_close(contactDB);
}
}
我知道那是放在那裏,但這是在一個人有一個字符串類來保存字符串對象,可以在此方法內使用的情況下。我沒有做任何字符串類,這就是爲什麼我感到困惑:( –