简体   繁体   中英

Subclassed NSArrayController bind to custom property

I am on XCode 10, Objective-C, Mac OSX, not iOS.

I have subclassed an NSArrayController to create a new property to bind to.

SHArrayController.h

@property (nonatomic) BOOL hasItems;

SHArrayController.m

- (BOOL)hasItems
{
    return ([self.arrangedObjects count] > 0);
}

If i bind anything to that property i doesn't get notified of changes. If i add an Object to the arrayController, "hasItems" should change.

This is how i add objects:

[self.arrayController willChangeValueForKey:@"hasItems"];
[self.arrayController addObject:SomeObject];
[self.arrayController didChangeValueForKey:@"hasItems"];

What am i doing wrong?

Edit: ArrayController is properly instantiated, so are the objects to add.

It was a fault of mine. The value did change and the notification works. I just made a mistake. The above implementation is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM