Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static NSString *kNoteObservationContext = @"NoteObservationContext";
- static NSString *kNoteCompletedKey = @"completed";
- - (void)setTest:(Test *)test
- {
- if (m_test == test)
- {
- return;
- // Nothing to do for the same object
- }
- [m_test removeObserver:self forKeyPath:kNoteCompletedKey context:&kNoteObservationContext];
- m_test = test;
- [test addObserver:self forKeyPath:kNoteCompletedKey options:NSKeyValueObservingOptionNew context:&kNoteObservationContext];
- }
- #pragma mark - KVO
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
- // observing changes to the model object so that background image can be changed.
- if (!(context == &kNoteObservationContext)) {
- [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
- }
- if (self.test.completedStatus)
- {
- self.cellBackgroundImage.image = [self completedBackgroundImage];
- }
- else
- {
- self.cellBackgroundImage.image = [self defaultBackgroundImage];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement