将 sqlite 数据加载到详细视图中。数据不会改变。帮助
我是编程新手,我正在遵循一个教程,该教程将数据从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一些问题:
您从查询中获得了正确的信息吗?通过直接从命令行查询数据库来检查这一点。
您是否在表格视图中呈现数据?表视图不会立即刷新。您应该调用 [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.
从您的代码中,您将 isDetailViewHydrated 设置为 YES,但您是否曾将其设置为 no ?
From your code you are setting isDetailViewHydrated to YES but do you ever set it to no?