将 sqlite 数据加载到详细视图中。数据不会改变。帮助

发布于 2024-10-30 18:11:44 字数 1134 浏览 1 评论 0原文

我是编程新手,我正在遵循一个教程,该教程将数据从 sqlite 数据库加载到表(名称)中,然后在选择时加载显示更多数据(地址等)的详细视图。

我的问题是,当我第一次在详细视图中加载数据时,它工作正常,但是当我尝试在另一个表项(名称)上再次加载数据时,详细视图会加载第一批数据,并且在重新启动之前不会更改模拟器。即

第一个选择: 表“名称 1”推送详细视图“地址 1”工作正常。

第二次选择: 表“名称2”推送详细视图“地址1”数据没有变化。

这是我的代码;

-(void) HydroDetailViewData { 如果(isDetailViewHydrated)返回;

if (detailStmt == nil) {
    const char *sql = "Select ClubAddress from clubNames Where clubID = ?";
     if (sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) !=SQLITE_OK)
         NSAssert1(0, @"Error while creating detail view statment. '%s'", sqlite3_errmsg(database));
     }
sqlite3_bind_int(detailStmt, 1, clubID);

if (SQLITE_DONE != sqlite3_step(detailStmt)) {
    const char *db_text = sqlite3_column_text(detailStmt, 0);
    NSString *address = [NSString stringWithUTF8String: db_text];
    self.ClubAddress = address;
}
else
    NSAssert1(0, @"Error while getting the address of club. '%s'", sqlite3_errmsg(database));
sqlite3_reset(detailStmt);

isDetailViewHydrated = YES;
}

我尝试释放该变量,但当我尝试推送详细视图时,我收到编译器警告并且应用程序崩溃。

任何帮助将不胜感激。 谢谢

I'm new to programming and I'm following a tutorial that loads data from sqlite database into a table (name) and then when selected loads detailed view showing more data (Address etc).

My problem is that when I first load the data in the detailed view it works fine however when I try to load data again on a another table item (name) the detailed view loads with the first lot of data and does not change until I restart the simulator. i.e.

first selection:
table "Name 1" push detailed view "Address 1" works fine.

second selection:
table "Name 2" push detailed view "Address 1" data does not change.

Here is my code;

-(void) hydrateDetailViewData {
if (isDetailViewHydrated) return;

if (detailStmt == nil) {
    const char *sql = "Select ClubAddress from clubNames Where clubID = ?";
     if (sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) !=SQLITE_OK)
         NSAssert1(0, @"Error while creating detail view statment. '%s'", sqlite3_errmsg(database));
     }
sqlite3_bind_int(detailStmt, 1, clubID);

if (SQLITE_DONE != sqlite3_step(detailStmt)) {
    const char *db_text = sqlite3_column_text(detailStmt, 0);
    NSString *address = [NSString stringWithUTF8String: db_text];
    self.ClubAddress = address;
}
else
    NSAssert1(0, @"Error while getting the address of club. '%s'", sqlite3_errmsg(database));
sqlite3_reset(detailStmt);

isDetailViewHydrated = YES;
}

I have tried releasing the variable but I get compiler warnings and the app crashes when I try to push detailed view.

Any help would be greatly appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟酒忠诚 2024-11-06 18:11:44

我有一些问题:

您从查询中获得了正确的信息吗?通过直接从命令行查询数据库来检查这一点。

您是否在表格视图中呈现数据?表视图不会立即刷新。您应该调用 [tableView reloadData] 来执行此操作。如果您对此还有疑问,请查看表视图编程指南。

您可以发布将崩溃的 ViewController 推送到的位置的代码片段吗?

如果您因释放对象而崩溃,您最好查看开发人员文档中的内存管理编程指南。

I've got some questions:

Are you getting the correct information from your query? Check that out by querying the db directly from the command line.

Are you presenting the data in table views? Table views don't refresh instantaneously. you should call [tableView reloadData] to do so. Check Table View Programming guide if you have further doubts with that.

Can you post the code snippet where you push the that ViewControllers that crash?

If you are getting crashes for releasing object, you'd better take a look at the memory management programming guide on the Developer documentation.

好倦 2024-11-06 18:11:44

从您的代码中,您将 isDetailViewHydrated 设置为 YES,但您是否曾将其设置为 no ?

From your code you are setting isDetailViewHydrated to YES but do you ever set it to no?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文