I’m trying to do something thats fairly simple but I can’t see the best way to do it. I have a uitableview with two cell’s, the first has a uitextfield in the contextview with the input view set as uidatepicker. The cell maps back to a nsmanageobject date property. The nsmanagedobject has a dependent property which is the difference in days between todays date and the date selected. This value is displayed in the second cell when the view loads.
The problem is that when the user changes the date in the first cell the second cell is not updated automatically.
Firstly I thought I could just call setNeedsDisplay on the uitableview. But this seems rather heavy handed.
So I’ve been reading up on KVO and I’ve not managed to find a good example of a solution to my problem yet.
I’m using fetchresultscontrollers for my tableviews. I tried to implement a key path dependency as shown in the iPhone docs but this hasn’t been successful.
for example…
+ (NSSet *)keyPathsForValuesAffectingDaysRemaining
{
NSLog(@"keyPathsForValuesAffectingDaysRemaining");
return [NSSet setWithObjects:@"dateOfOccasion", nil];
}
-(NSNumber *)daysRemaining {
return [self.dateOfOccasion daysFromNow]; //simple calendar calc.
}
Could someone point me in the right direction of an appropriate solutions to a relatively simple problem.
Thanks,
Gary
I think implementing a
[[self tableView] reloadData]strategically should fix the problem. As soon as you change the object incell1, I would assume you basically save the change globally or in Coredata. Simply reloading the tableView in that configuration should fix the issue.In your case, since you are implementing the
NSFetchedResultsController, I would assumeobjectDidChangewould fire when you change the value of that object. AtableView reloadDatawould be a nice implementation there !