我有 UITableView
部分的问题 . 我正在使用 NSFetchedResultsController
填充表格,我在初始化时提供了 sectionNameKeyPath:
.
基本上,我有一个包含一个部分的表视图,但是当用户点击单元格时,它正在更改一个核心数据属性,并应创建第二个部分 . 我想我已经完成了这个但是......
当我点击第一个单元格时,它会创建上面的新部分(这就是应该如何),但是当我第一次点击另一个单元格时,它会在表格视图的底部创建一个部分 . 您可以在下面的屏幕截图中预览:
以下是我的应用程序中的一些Table View委托方法:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[_fetchedResultsController sections] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[[_fetchedResultsController sections] objectAtIndex:section] name];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
我的问题是: How to manually provide section order?
1 回答
对于此示例,解决方案非常简单 - 在
NSFetchedResultsController
sort descriptors数组中将一个NSSortDescriptor
添加到现有的一个NSSortDescriptor
.所以现在,获取的数据首先按部分排序,然后按字母顺序排序 .