NSFetchedResultsController: The fetched object at index x has an out of order section name

半世苍凉 提交于 2019-12-06 16:09:29

I am pretty sure your sorting code can be greatly simplified. But maybe that is a different question. Anyway, it is not clear, if startDate is set and there are too many variables which make the algorithm very convoluted. Could you try to refactor just using a date and a section identifier? The section identifier should sort in the correct way - you can add the logic to display some customised string elsewhere.

Here is something you should try. Eliminate the if (!tmp) check - I had some luck with that fixing this sample code for my purposes.

Finally, it is not clear how you update the FRC when the date changes. Make sure the data that you expect to change is updated as intended.

Your main issue seems to be triggering an update process to run and modify your data store contents.

When you update the sectionIdentifier and sortKey you can store the date they are calculated against and compare the date when requested to check it's still valid. This gives you an easy way to check if any updates are required when you receive a trigger to tell you that something has changed and you need to verify.

For the triggers, you need to consider the app coming to the foreground, significant time changes, and just the day changing while the app is open. So you can trigger from the app delegate (or observing activation), and you can observe UIApplicationSignificantTimeChangeNotification and you can configure a timer (when the app is activated) which counts down to the end of the day (invalidate this when the app goes to background).

Now you have triggers and action to take as a result. But, your view controller won't always exist when a trigger is received, so consider using a data update controller to manage this process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!