【问题标题】:Why can't I get this SQLite code to load the proper data for my detail view?为什么我不能让这个 SQLite 代码为我的详细视图加载正确的数据?
【发布时间】:2011-01-27 14:27:22
【问题描述】:
- (void) hydrateDetailViewData {
//if detail view is hydrated then do not get it from database
if(isDetailViewHydrated) return;

if(detailStmt == nil) {
    const char *sql = "select snapTitle, snapDesc from Snap where snapID =?";
    if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) != SQLITE_OK)
        NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(database));
    NSLog(@"SQLite= %d", sqlite3_step(detailStmt)); 

}

if (sqlite3_step(detailStmt) == SQLITE_ROW)//execute sql statement on database, and make sure it executed properly.
{
    self.snapDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 1)];
}   

看看上面的代码,有人能告诉我有什么问题吗?为什么我不能让它加载到我的 detailview 上?我基本上遵循了 iphone sdk 文章上的教程..但是我有这个问题不知道为什么会出错。

如果你们需要看,我什至可以发送我的项目。

错误信息:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib named "DetailView"'
2010-03-15 16:35:55.202 Snap2Play[58213:20b]

【问题讨论】:

    标签: iphone iphone-sdk-3.0 sqlite ios-simulator


    【解决方案1】:

    你的错误和你的问题不匹配,据我所见,该错误与上述代码无关。

    错误与对loadViewFromNibNamed:bundle: 的调用有关 - 我猜您的项目中没有名为 DetailView.xib 的 xib 文件

    【讨论】:

    • 我确实有具有正确文件名的 xib..我需要帮助严重..我不知道我哪里出错了..
    • 当您的代码崩溃时,调试器中的堆栈跟踪是什么?如果您在问题中提出这一点,可能会有更多人能够提供帮助?
    • 另外,如果您在问题中添加文章链接,我可以尝试在我的机器上重现它,看看可能有什么问题?
    • iphonesdkarticles.com/2008/10/… 我按照教程进行操作..但是我没有得到 int,而是得到了字符..
    【解决方案2】:

    您似乎缺少将参数绑定到 SQL 选择语句的语句。你有这个:

    const char *sql = "select snapTitle, snapDesc from Snap where snapID =?";
    

    但您从未在我能看到的任何地方设置 snapID 的值。在执行查询之前,您需要这样的语句:

    sqlite3_bind_int(detailStmt, 1, snapID);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      相关资源
      最近更新 更多