문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top