You need to set a delegate on the NSFetchedResultsController
. See the docs which give details on how to set up the delegate methods and respond to changes in the table.
FetchedResultsController update after changing of dependent entity
-
30-06-2023 - |
سؤال
Assume I have following class model.
I have UITableView
which displays data from Days
table in following way:
Monday 02.03
5 lessons
Wednesday 04.03
3 lessons
The task is straightforward. I can create a FetchedResultsController like this and use it as data source for TableView:
[Days MR_fetchAllSortedBy:@"day" ascending:YES withPredicate:filter groupBy:nil delegate:self]
later:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.lessonsLabel.text = [NSString stringWithFormat:@"%d lessons", [day.dayToLesson count]];
Using this approach I can get desired output. Additionally, I'd like to refresh TableView if number of lessons changed (someone inserted in Lessons table). How can I achieve this behavior?
المحلول
لا تنتمي إلى StackOverflow