从 Core Data 支持的 UITableView 中的某个部分删除所有对象不会触发选择删除?
我在使用 NSFetchedResultsController 管理核心数据支持的 UITableView 中的部分时遇到问题。
我的表视图可以有 2 个部分,第一个是静态部分,有条件地显示。第二部分由获取的结果控制器填充。我使用以下内容来确定要显示的部分数。如果我删除第二部分中所有获取的对象,我希望该部分也被删除。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
NSInteger numberOfSections = 0;
if (self.locationEnabled) numberOfSections++;
if ([[[self.fetchedResultsController sections] lastObject] numberOfObjects]) numberOfSections++;
return numberOfSections;
}
这种方法的问题在于,该数据源方法通知表它应该显示 1 个部分,因为没有剩余的提取对象,但删除最后一个对象永远不会通过提取结果管理器委托方法触发该部分的删除。
如何触发部分删除以避免收到 UIKit 不一致错误?
编辑:我应该指出,我将sectionNameKeyPath设置为nil,因为结果与section by没有任何共同之处。
I'm having a problem managing the sections in my Core Data backed UITableView, using an NSFetchedResultsController.
My table view can have 2 sections, the first is a static section and is displayed conditionally. The second section is being populated with the fetched results controller. I'm using the following to determine how many sections to display. If I delete all of the fetched objects in the second section, I would expect that section to be deleted as well.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
NSInteger numberOfSections = 0;
if (self.locationEnabled) numberOfSections++;
if ([[[self.fetchedResultsController sections] lastObject] numberOfObjects]) numberOfSections++;
return numberOfSections;
}
The problem with this approach is that this datasource method is informing the table that it should be displaying 1 section because there are no fetched objects remaining, but removing the last object never triggered a deletion of the section through the fetched results manager delegate methods.
How do I trigger a section deletion to avoid receiving UIKit inconsistency errors?
Edit: I should point out that I have sectionNameKeyPath set to nil since the results don't share anything in common to section by.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论