我有一个表视图,它是根据月份和年份分组的。为此,我在NSFetchedResultsController中创建了一个瞬态属性和一个对应的排序描述符,这有助于我根据月份和年份进行分组。表视图工作得很好,并且按照我想要的那样显示部分(使用titleForHeaderInSection)。
我想在表视图中添加一个索引,但目前在这里停滞不前。我相信唯一的方法就是:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView那么如何给它一个包含所有部分名称的数组呢?
附言:这是我的第一篇文章。
发布于 2011-10-27 18:07:42
下面是我所做的:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
NSInteger lastSectionIndex = [self.tableView numberOfSections] - 1;
if (lastSectionIndex == -1) {
return nil;
}
NSMutableArray *sectionNames = [[NSMutableArray alloc] init];
NSString *sectionName = nil;
for (int i = 0; i <= lastSectionIndex; i++) {
sectionName = [[[self.fetchedResultsController sections] objectAtIndex:i] name];
[sectionNames addObject:sectionName];
}
return sectionNames;}
https://stackoverflow.com/questions/7867468
复制相似问题