NSFetchedResultsController order not changed when it should
I have a NSFetchedResultsController
(or NSFRC) that is really pretty standard;
NSDate
field (descending) Up next the data gets updated:
NSFRC
nicely passes on the changes to the TableView, except for the order changes . reloadData()
, data is changed, the order isn't. I would expect the delegate for example to swap the first and second row because the second row's date value is now higher than the first one.
If I re-open the ViewController (so the fetch is done again on a new VC and NSFRC
) the order does change as expected. But thats anything but intuitive for the user.
Could anyone please point me into possible places to search for my mistake?
Just to reiterate:
Here's two screenshots, the second line (date) is also the sort order. The second image shows updated data but a wrong sort order.
Before
After
When your data changes you may need to nil the NSFRC
and let it do its thing. For example. Lets say that you have a function which changes the order of your items. If you are using standard Apple code, you should have something like this
func updateSort () {
_fetchedResultsController = nil //Here is the magic
tableView.reloadData()
}
// MARK: - Core Data
var fetchedResultsController:NSFetchedResultsController {
if _fetchedResultsController != nil {
return _fetchedResultsController!
}
// do your basic initialization and set the delegate and return it
return _fetchedResultsController!
}
var _fetchedResultsController: NSFetchedResultsController? = nil
链接地址: http://www.djcxy.com/p/36160.html
上一篇: 使用NSFetchedResultsController和SortDescriptors对部分内的项目进行排序