我有UITableViewController
视图,它使用SQLLite DB作为数据源来构建其行,如下所示。
我也有UIViewController
更新了UITableViewController
使用的SQL Lite数据库。但是,它不会更新UITableView
,因为我认为它在查询SQLLite时会知道更改。
我注意到在SQL lite DB中添加条目后从UIViewController
快速切换到UITableViewController
后,我注意到应用程序“有时”崩溃的问题。
我是目标C和iOS的新手,但我知道Java / Android。在这种情况下,我需要通知视图基础数据源发生了更改(使用notify)。否则可能会发生崩溃/错误。
我需要在iOS中做同样的事情,如何做?
- (int)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
MyAPPAppDelegate *appDelegate = (MyAPPAppDelegate *)[[UIApplication sharedApplication] delegate];
return [appDelegate.dataModel countMessages] ;
}
最佳答案
从数据库中获取记录后,只需在新记录的reloads
table data
下面写一行。
[tbl reloadData];
关于ios - 在基础SQLite数据库更改时更新UITableView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15654147/