UITableView中的部分无法正常显示 [英] Sections in UITableView not showing properly

查看:112
本文介绍了UITableView中的部分无法正常显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 UITableView 部分的问题。我正在使用 NSFetchedResultsController 来填充表格,我在初始化时提供了 sectionNameKeyPath:

I have a problem with UITableView sections. I'm using NSFetchedResultsController to populate table and I've provided sectionNameKeyPath: on initialization.

基本上我有一个包含一个部分的表视图,但是当用户点击单元格时,它正在改变一个核心数据属性并应该创建第二部分。我想我已经完成了这个但是......

Basiclly I have a table view with one section but when user taps on cell it is changing one core data attribute and should create second section. I think I've accomplished this but...

当我点击第一个单元格时,它会在上面创建新的部分(这是应该的样子)但是当我的第一个tap在另一个单元格上,它在表格视图的底部创建了一个部分。您可以在下面的屏幕截图中预览:

When I tap on the first cell it creates new section above (this is how it should be) but when my first tap is on another cell it creates section at the botton of table view. You can preview this on screenshots below:

以下是我的应用程序中的一些Table View委托方法:

Here are some Table View delegate methods from my app:

-(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];
}

我的问题是:如何手动提供分段订单?

推荐答案

对于此示例解决方案非常直接 - 添加一个 NSSortDescriptor NSFetchedResultsController 排序描述符数组中的现有数据。

For this example solution was pretty straight - adding one NSSortDescriptor to existing one in NSFetchedResultsController sort descriptors array.

所以现在,获取的数据首先按部分排序,然后按字母顺序排序。

So now, fetched data is firstly sorted by section and then it is sorted alphabetically.

这篇关于UITableView中的部分无法正常显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆