Core Data: changes in one UITableView/entity not being recognized by other “indirectly” related UItableviews/entity

血红的双手。 提交于 2019-12-04 23:26:48

Your fetch request for VC2 should be a 'courses' request not a 'years' request. A fetched results controller will only notice changes and call your delegate methods if the results set returned from its fetch request changes. When you add a new course, no new years are created so the fetched results controller is not propagating any changes.

Assuming that your course entity has a 'year' relationship then you can configure your fetched results controller to group by year by init'ing it like this:

 NSFetchedResultsController *myController = [[NSFetchedResultsController alloc] 
                                 initWithFetchRequest:<a courses fetch request> 
                                 managedObjectContext:context
                                   sectionNameKeyPath:@"year"
                                            cacheName:<cache name or nil>];

Then alter your tableview datasource methods to use the section information from the frc to create sections for years and populate the sections with courses. If you do it this way then whenever a new course is added the frc will notify vc2 via the delegate methods.

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