Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么我的UITableViewController没有';不显示数据库中的数据?_Ios_Database_Sqlite_Uitableview - Fatal编程技术网

Ios 为什么我的UITableViewController没有';不显示数据库中的数据?

Ios 为什么我的UITableViewController没有';不显示数据库中的数据?,ios,database,sqlite,uitableview,Ios,Database,Sqlite,Uitableview,在UITableViewController中显示从数据库获取的数据时出现问题。我的方法是: -(void)createDataFromDB { self.characterData = [[NSMutableArray alloc]initWithCapacity:20]; @try { // give the database path NSString * path = [[NSBundle mainBundle] resourcePath]; NSStr

在UITableViewController中显示从数据库获取的数据时出现问题。我的方法是:

-(void)createDataFromDB
{
   self.characterData = [[NSMutableArray alloc]initWithCapacity:20];

@try
{
    // give the database path
    NSString * path = [[NSBundle mainBundle] resourcePath];

    NSString * pathDB = [path stringByAppendingPathComponent:@"Characters.rdb"];
    const char * pathStr = [pathDB UTF8String];

    // open the db

    BOOL success = sqlite3_open(pathStr, &db);
    if(!success)
    {
        NSLog(@"Database cannot open \n");
    }

    // make a sql query

    const char * queryStr = "SELECT * FROM characters";

    NSLog(@"Query prepared \n");
    // declare a statement

    sqlite3_stmt * statement;

    sqlite3_prepare(db, queryStr, -1, &statement, NULL);

    if(!success)
    {
        NSLog(@"Query statement cannot prepare \n");
    }
    //run a query and iterate through the results

    while (sqlite3_step(statement) == SQLITE_ROW)
    {



        NSString * nameStr = [[NSString alloc ]initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
        NSString * typeStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
        NSString * availabilityStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
        NSString * imageStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];
        NSString * iconStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)];

        Character * characters =[[Character alloc] initWithName: nameStr
                                                        andType: typeStr
                                                andAvailability:availabilityStr
                                                       andImage: imageStr
                                                        andIcon:iconStr];
        [self.characterData addObject: characters];

       NSLog(@" %@", nameStr);

         //NSLog(@"%@", characters.characterType);
         //NSLog(@"%@", characters.availability);
        // NSLog(@"%@", characters.image);

    }

}
@catch (NSException *exception)
{
    NSLog(@"Database Error %s", sqlite3_errmsg(db));
}

@finally
{
    // close the db
    sqlite3_close(db);
}
}
我实现原型单元的方法是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSLog(@" Cell created");


if(cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                  reuseIdentifier:@"Cell"];
}


Character * character = self.characterData [indexPath.row];
NSLog(@"%@", character.name);
cell.textLabel.text = character.name;
cell.imageView.image = character.icon;

NSLog(@"%@", character.name);

return cell;
}

我已经尝试了很多次,但在我的代码中找不到错误。该查询构建得很好,因为它可以在我的MesaSQLite数据库上运行,但我尝试在控制台上打印一些内容,但它没有显示任何内容。请帮帮我!谢谢

其他UITable代码在哪里,比如告诉UITableView有多少行等所需的UITableDelegate方法。。。?你有很多NSLog语句,控制台上出现了什么?这是我的UITable代码…-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{return 1;}-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{return[self.characterData count];}我在代码中放了很多NSLog来检查错误的位置,但没有显示任何内容…请帮助我,因为我不明白!你在哪里调用createDataFromDB例程?我可能错了,但可能是你有一个竞争条件!只是出于好奇,当你调用时会发生什么[reloadData];在createDataFromDB例程的末尾?我在ViewDidLoad方法中调用我的createDataFromDB例程。我尝试添加reloadData,但它仍然不起作用…控制台上没有显示任何内容…似乎一切正常,但表为空