简体   繁体   English

具有NSFetchedResultsController的UITableView保留没有对象的节的标题

[英]UITableView with NSFetchedResultsController keep header for section without objects

I've got a bunch of NSManagedObjects that are divided into sections in a UITableView. 我有一堆NSManagedObjects,它们在UITableView中分为多个部分。

[Section Header 0]
[NSManagedObject]
[NSManagedObject]
[NSManagedObject]
[Section Header 1]
[NSManagedObject]
[Section Header 2]
[NSManagedObject]
[NSManagedObject]
[NSManagedObject]

The user can edit the objects on a per-section basis, including deleting them. 用户可以按部分编辑对象,包括删除它们。 Say I delete the [NSManagedObject] in [Section 1] above. 说我删除上面[Section 1][NSManagedObject] This updates my NSFetchedResultsController and removes both the row and the section, including the section header. 这将更新我的NSFetchedResultsController并删除行和节,包括节标题。

Is there a way to keep a blank section with any objects? 有没有一种方法可以将任何对象保留为空白部分? I've considered putting in some code which sets a minimum count for sections, but the issue is that it won't be in sync with the NSFetchedResultsController. 我已经考虑过放置一些代码来设置节的最小数量,但是问题是它不会与NSFetchedResultsController同步。 Adding an extra section would just add it to the bottom, but I'd like to add it after the first section, regardless of whether there are one or more sections after. 添加一个额外的部分只会将其添加到底部,但是我想将其添加到第一部分之后,而不管其后是否有一个或多个部分。

The objects are all server-driven, so I'd like to make so I won't have a lot of hardcoded sections in there. 这些对象都是服务器驱动的,因此我想制作这样,因此那里没有很多硬编码部分。

Thanks. 谢谢。

You should include an attribute or a relationship in your data model to keep track of the sections. 您应该在数据模型中包括一个属性或关系,以跟踪各个部分。 Seeing that you group your user, there must be a criterion that you can model in your data. 看到您对用户进行了分组,必须有一个可以在数据中建模的条件。

Then initialize the NSFetchedResultsController to with the appropriate sectionNameKeyPath . 然后初始化NSFetchedResultsController用适当的sectionNameKeyPath Use Apple's plain vanilla code to display section information, if any. 使用Apple的普通香草代码显示部分信息(如果有)。

What you actually display in each section is still up to you. 您实际在每个部分中显示的内容仍由您决定。 (It's what you put in your datasource methods). (这就是您放入数据源方法的内容)。 But at least you can have a consistent system of sections and grouping of objects. 但是至少您可以拥有一致的分区和对象分组系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UITableView中带有NSFetchedResultsController的附加部分 - Additional section in UITableView with NSFetchedResultsController 使用 NSFetchedResultsController 的 UITableView 部分中的意外标题视图 - Unexpected Header View in UITableView's section using NSFetchedResultsController 将NSFetchedResultsController与UITableView中的特定部分相关联 - Associate NSFetchedResultsController with specific section in UITableView 重载UITableView而不重载Section Header - Reloading UITableView without reloading Section Header 不使用tableView更改UITableView节头:titleForHeaderInSection - Changing UITableView section header without tableView:titleForHeaderInSection 刷新UITableView而不刷新节头 - Refresh UITableView without refresh section header 重新加载UITableView而不重新加载标头部分 - Reload UITableView without reloading header section UITableView-防止第0部分的标题标签碰到表格的标题 - UITableView - keep header label of section 0 from touching the header of the table NSFetchedResultsController无法将对象正确插入UITableView - NSFetchedResultsController not inserting objects into UITableView correctly 从NSFetchedResultsController中删除部分时更新UITableView - update UITableView when section is removed from NSFetchedResultsController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM