为什么我不能得到这个SQLite的代码加载了我的详细信息视图正确的数据?(Why can't

2019-11-03 06:13发布

- (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的article..but教程但我有这个不知道为什么错误。

如果能跟大家需要看看我甚至可以把我的项目。

错误信息:

 *** 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]

Answer 1:

你的错误,你的问题不匹配,错误是什么,据我可以看到做上面的代码。

该错误是将呼叫做loadViewFromNibNamed:捆绑: -我猜你没有在您的项目称为DetailView.xib一个XIB文件



Answer 2:

它看起来像你缺少一个语句的参数绑定到你的SQL SELECT语句。 你有这样的:

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

但你永远不设置snapID值的任何地方,我可以看到。 在执行查询之前,你需要这样的语句:

sqlite3_bind_int(detailStmt, 1, snapID);


文章来源: Why can't I get this SQLite code to load the proper data for my detail view?