我有 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/