Question

Database scheme

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top