Created
October 8, 2010 15:59
-
-
Save billymeltdown/617020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)startObserving | |
{ | |
// start observing the entriesController's selection property, | |
// so we can properly update the third pane with a populated | |
// entry view once an entry is selected | |
[entriesController addObserver:self | |
forKeyPath:@"selection" | |
options:NSKeyValueObservingOptionNew | |
context:EntryWindowContext]; | |
} | |
- (void)stopObserving | |
{ | |
[entriesController removeObserver:self forKeyPath:@"selection"]; | |
} | |
- (void)observeValueForKeyPath:(NSString *)keyPath | |
ofObject:(id)object | |
change:(NSDictionary *)change | |
context:(void *)context | |
{ | |
//DLog(@"got a change in %@ to %@", keyPath, [object valueForKey:keyPath]); | |
if (context == EntryWindowContext) | |
{ | |
if ([keyPath isEqual:@"selection"]) | |
{ | |
DLog(@"selection changed..."); | |
id selectedEntry = [object valueForKey:@"selection"]; | |
DLog(@"selection: %@", selectedEntry); | |
if (selectedEntry != nil && [selectedEntry isKindOfClass:[Entry class]]) { | |
DLog(@"presenting entry view"); | |
[self showEntryView]; | |
} else { | |
DLog(@"showing no selection view"); | |
[self showNoSelectionView]; | |
} | |
} | |
} | |
} | |
- (void)showNoSelectionView | |
{ | |
// make sure that entry view itself is not the current subview, by removing it | |
[entryView removeFromSuperview]; | |
// add our no-selection view as the subview to the entry display pane | |
[entryViewPane addSubview:noEntryView]; | |
// set the frame of the new view to match the parent, in case it's changed | |
[noEntryView setFrame:[entryViewPane bounds]]; | |
} | |
- (void)showEntryView | |
{ | |
[noEntryView removeFromSuperview]; | |
[entryViewPane addSubview:entryView]; | |
[entryView setFrame:[entryViewPane bounds]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment