ios - 当底层 SQLite DB 更改时更新 UITableView

标签 ios objective-c xcode ios6

我有 UITableViewController View ,它使用 SQLLite DB 作为数据源来构建其行,如下所示。

我还有 UIViewController 来更新 UITableViewController 使用的 SQL Lite DB。但是,它不会更新 UITableView,因为我假设它在查询 SQLLite 时会知道更改。

当我在 SQL lite DB 中添加条目后快速从 UIViewController 切换到 UITableViewController< 时,我注意到应用程序“有时”崩溃。/.

我是 Objective C 和 iOS 的新手,但我了解 Java/Android。在这种情况下,我需要通知 View 底层数据源发生了变化(使用notify)。否则可能会发生崩溃/错误。

我需要在 iOS 中执行相同的操作吗?我该怎么做?

- (int)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{  
    MyAPPAppDelegate *appDelegate = (MyAPPAppDelegate *)[[UIApplication sharedApplication] delegate];

    return [appDelegate.dataModel countMessages]  ;
} 

最佳答案

从数据库中获取记录后,只需编写以下行即可使用新记录重新加载表数据

[tbl reloadData];

关于ios - 当底层 SQLite DB 更改时更新 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654147/

相关文章:

ios - 如何将数据从Alamofire闭包迁移到主线程

ios - Autolayout 在模拟器上持续存在 - XCode

objective-c - 如何获取当前音频输出设备的当前音量?

ios - 图像不是从一个 VC 到另一个 VC

xcode - 如何在基于文档的 Mac 应用程序中向我的文档添加自定义文档图标?

ios - 在 iOS10 上滚动正文时,我可以阻止隐藏底部菜单栏吗?

iphone - 以正确的方式检测 UITextField 中的退格键

ios - EXC_BAD_ACCESS 关于 mergeChangesFromContextDidSaveNotification

objective-c - 创建自定义 NSWindow 界面

xcode - 自定义 TableViewCell 与高度变化的 subview