Skip to content

Commit 5b4731c

Browse files
committed
•  Clarify workaround for Apple Bug 7827354, which is closed as a duplicate of 3404770.
1 parent d1dda01 commit 5b4731c

3 files changed

+19
-6
lines changed

SSYArrayController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
111111
SELECTION METHODS
112112
113-
Provides -selectFirstArranged, -hasSelection.
113+
Provides -selectFirstArranged
114114
115115
TABLE FONT SIZE
116116

SSYMoreObserveableArrayController.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
@brief Workaround for Apple Bug ID 7827354, which was closed as a duplicate
77
of 3404770, in NSArrayController
88
9-
@details Provides a -hasSelection property which actually works.
9+
@details Provides two properties for observing content. However,
10+
even these don't work if you stick them into +keyPathsForValuesAffecting<Key>.
11+
You must observe them directly.
1012
*/
1113

12-
@property (assign, readonly) BOOL hasSelection ;
14+
@property (readonly) BOOL hasSelection ;
15+
@property (readonly) NSInteger countOfArrangedObjects ;
1316

1417
@end

SSYMoreObserveableArrayController.m

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@interface SSYMoreObserveableArrayController ()
44

55
@property (assign) BOOL hasSelection ;
6+
@property (assign) NSInteger countOfArrangedObjects ;
67

78
@end
89

@@ -28,16 +29,18 @@ - (void)awakeFromNib {
2829
[self addObserver:self
2930
forKeyPath:@"selectedObjects"
3031
options:0
31-
context:NULL] ;
32+
context:[self class]] ;
3233
}
3334

3435
- (void)observeValueForKeyPath:(NSString *)keyPath
3536
ofObject:(id)object
3637
change:(NSDictionary *)change
3738
context:(void *)context {
38-
if ([keyPath isEqualToString:@"selectedObjects"]) {
39+
if ((context == [self class]) && [keyPath isEqualToString:@"selectedObjects"]) {
3940
NSInteger selectionCount = [[self selectedObjects] count] ;
40-
[self setHasSelection:(selectionCount > 0)] ;
41+
BOOL hasSelection = (selectionCount > 0) ;
42+
self.hasSelection = hasSelection ;
43+
/*SSYDBL*/ NSLog(@" set hasSelection to %hhd", self.hasSelection) ;
4144
}
4245

4346
[super observeValueForKeyPath:keyPath
@@ -46,4 +49,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
4649
context:context] ;
4750
}
4851

52+
- (void)rearrangeObjects {
53+
[super rearrangeObjects] ;
54+
55+
self.countOfArrangedObjects = ((NSArray*)self.arrangedObjects).count ;
56+
/*SSYDBL*/ NSLog(@" set countOfArrangedObjects to %ld", self.countOfArrangedObjects) ;
57+
}
58+
4959
@end

0 commit comments

Comments
 (0)