3
3
@interface SSYMoreObserveableArrayController ()
4
4
5
5
@property (assign ) BOOL hasSelection ;
6
+ @property (assign ) NSInteger countOfArrangedObjects ;
6
7
7
8
@end
8
9
@@ -28,16 +29,18 @@ - (void)awakeFromNib {
28
29
[self addObserver: self
29
30
forKeyPath: @" selectedObjects"
30
31
options: 0
31
- context: NULL ] ;
32
+ context: [ self class ] ] ;
32
33
}
33
34
34
35
- (void )observeValueForKeyPath : (NSString *)keyPath
35
36
ofObject : (id )object
36
37
change : (NSDictionary *)change
37
38
context : (void *)context {
38
- if ([keyPath isEqualToString: @" selectedObjects" ]) {
39
+ if ((context == [ self class ]) && [keyPath isEqualToString: @" selectedObjects" ]) {
39
40
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 ) ;
41
44
}
42
45
43
46
[super observeValueForKeyPath: keyPath
@@ -46,4 +49,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
46
49
context: context] ;
47
50
}
48
51
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
+
49
59
@end
0 commit comments