我有一个tableview按部分日期的问题。 我拿了苹果的例子:DateSectionTitles日期部分标题不起作用
我不在乎年。我不需要一天一天的时间。 所以我适应我的代码这样的:
在我CoreData类:
- (NSString *)sectionIdentifier {
[self willAccessValueForKey:@"sectionIdentifier"];
NSString *tmp = [self primitiveSectionIdentifier];
[self didAccessValueForKey:@"sectionIdentifier"];
NSLog(@"!Temp");
if (!tmp) {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[self timeStamp]];
tmp = [NSString stringWithFormat:@"%d", ([components month]*100) + [components day]];
[self setPrimitiveSectionIdentifier:tmp];
}
return tmp;}
,并在我的主控制器我titleForHeaderInSection方法:
NSInteger month = numericSection/100;
NSInteger day = numericSection - (month * 100);
NSString *titleString = [NSString stringWithFormat:@"%d %d",day, month];
return titleString;
但是当我运行我的应用我有此消息:
CoreData:error:(NSFetchedResultsController)节的名称键路径返回nil值' sectionIdentifier”。对象将被放置在未命名的部分
你知道为什么吗? 感谢您的帮助!
没有打印。它不进入 - (NSString *)sectionIdentifier方法:/ – Pierre
好吧,太好了。你发现了这个问题。 – Mundi
是的,但我不知道为什么:D – Pierre