NSCollectionView: Can the same object not be in the array more than once or is this a bug?
Posted
by Sean
on Stack Overflow
See other posts from Stack Overflow
or by Sean
Published on 2009-09-30T21:13:24Z
Indexed on
2010/04/15
3:13 UTC
Read the original article
Hit count: 289
I may be doing this all wrong, but I thought I was on the right track until I hit this little snag. Basically I was putting together a toy using NSCollectionView and trying to understand how to hook that all up using IB. I have a button which will add a couple of strings to the NSArrayController:
The first time I press this button, my strings appear in the collection view as expected:
The second time I press the button, the views scroll down and room is made - but the items don't appear to get added. I just see blank space:
The button is implemented as follows (controller is a pointer to the NSArrayController I added in IB):
- (IBAction)addStuff:(id)control
{
[controller addObjects:[NSArray arrayWithObjects:@"String 1",@"String 2",@"String 3",nil]];
}
I'm not sure what I'm doing wrong. Rather than try to explain all the connections/binds/etc, if you need more info, I'd be grateful if you could just take a quick look at the toy project itself.
UPDATE: After more experimentation as suggested by James Williams, it seems the problem stems from having multiple objects with the same memory address in the array. This confuses either NSArrayController or NSCollectionView (not sure which). Changing my addStuff: to this resulted in the behavior I originally expected:
[controller addObjects:[NSArray arrayWithObjects:[NSMutableString stringWithString:@"String 1"],[NSMutableString stringWithString:@"String 2"],[NSMutableString stringWithString:@"String 3"],nil]];
So the question now, I guess, is if this is a bug I should report to Apple or if this is intended/documented behavior and I just missed it?
© Stack Overflow or respective owner