Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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/5/objective-c/22.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
Iphone UITableView未填充sqlite数据库列_Iphone_Objective C_Uitableview_Ios5_Xcode4.3 - Fatal编程技术网

Iphone UITableView未填充sqlite数据库列

Iphone UITableView未填充sqlite数据库列,iphone,objective-c,uitableview,ios5,xcode4.3,Iphone,Objective C,Uitableview,Ios5,Xcode4.3,下面是我用来用sqlite数据库中的列内容填充UITableView的方法的代码。但是,这在运行时没有给出错误,但在UITableView中仍然没有给出任何数据。如果有人能帮忙,我们将不胜感激 - (void)viewDidLoad{ [super viewDidLoad]; self.title = @"Strings List"; UITableViewCell *cell; NSString *docsDir; NSArray *dirPaths;

下面是我用来用sqlite数据库中的列内容填充UITableView的方法的代码。但是,这在运行时没有给出错误,但在UITableView中仍然没有给出任何数据。如果有人能帮忙,我们将不胜感激

- (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);
    }

}

我建议你通读一遍

您放入
viewDidLoad
中的大部分序列通常位于

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

当你拥有表视图的所有委托方法时,你正在使用的方法非常复杂,就像在面包上抹黄油一样

试试我的答案

让我知道它是否有效

干杯

如果您使用模拟器进行测试,请删除以前的构建并再次安装应用程序。它从文档目录中获取SQL文件。所以请试试这个,让我知道。谢谢

您是否检查了tableview或数据库是否存在问题?
您能从数据库中获取数据吗?检查您是否缺少任何在代码中连接sqlite的方法。

我知道这是放在那个里的,但在这种情况下,当一个人有一个strings类来保存可以在这个方法中使用的strings对象时。我没有做过任何字符串类,这就是我感到困惑的原因:(@BarinStroms在你提到的链接中只提到了应用程序deligates,我陷入的困境与uitableview有关:(我在回答中提到的是,DB和Xcode有时存在问题,可能连接不正确。除了我所描述的方法外,在处理数据库时最为人所知。