The problem is that the section identifier is calculated and cached from the todoDueDate
, but not updated automatically when the todoDueDate
changes.
The DateSectionTitles/APLEvent.m sample code from Apple shows how such an automatic update can be achieved.
In your case, you should add the following methods to the managed object subclass
ToDoItem
:
- (void)setTodoDueDate:(NSDate *)newDate
{
// If the todoDueDate changes, the section identifier become invalid.
[self willChangeValueForKey:@"todoDueDate"];
[self setPrimitiveValue:newDate forKey:@"todoDueDate"];
[self didChangeValueForKey:@"todoDueDate"];
// Set the section identifier to nil, so that it will be recalculated
// when the sectionIdentifier method is called the next time:
[self setPrimitiveValue:nil forKey:@"sectionIdentifier"];
}
+ (NSSet *)keyPathsForValuesAffectingSectionIdentifier
{
// If the value of todoDueDate changes, the section identifier may change as well.
return [NSSet setWithObject:@"todoDueDate"];
}