NSCollectionView draws nothing

Posted by PCWiz on Stack Overflow See other posts from Stack Overflow or by PCWiz
Published on 2009-10-21T00:25:02Z Indexed on 2010/03/09 4:51 UTC
Read the original article Hit count: 451

I'm trying to set up an NSCollectionView (I have done this successfully in the past, but for some reason it fails this time).

I have a model class called "TestModel", and it has an NSString property that just returns a string (just for testing purposes right now). I then have an NSMutableArray property declaration in my main app delegate class, and to this array I add instances of the TestModel object.

I then have an Array Controller that has its Content Array bound the app delegate's NSMutableArray. I can confirm that everything up to here is working fine; NSLogging:

[[[arrayController arrangedObjects] objectAtIndex:0] teststring]

worked fine.

I then have all the appropriate bindings for the collection view set up, (itemPrototype and content), and for the Collection View Item (view). I then have a text field in the collection item view that is bound to Collection View Item.representedObject.teststring. However NOTHING displays in the collection view when I start the app, just a blank white screen. What am I missing?

UPDATE: Here is the code I use (requested by wil shipley):

// App delegate class

@interface AppController : NSObject {

NSMutableArray *objectArray;
}
@property (readwrite, retain) NSMutableArray *objectArray;
@end

@implementation AppController
@synthesize objectArray;

- (id)init
{
    if (self = [super init]) {
    objectArray = [[NSMutableArray alloc] init];
    }
    return self;
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    TestModel *test = [[[TestModel alloc] initWithString:@"somerandomstring"] autorelease];
    if (test) [objectArray addObject:test];
}
@end

// The model class (TestModel)

@interface TestModel : NSObject {
NSString *teststring;
}
@property (readwrite, retain) NSString *teststring;
- (id)initWithString:(NSString*)customString;
@end

@implementation TestModel
@synthesize teststring;

- (id)initWithString:(NSString*)customString
{
    [self setTeststring:customString];
}

- (void)dealloc
{
    [teststring release];
}
@end

And then like I said the content array of the Array Controller is bound to this "objectArray", and the Content of the NSCollectionView is bound to Array Controller.arrangedObjects. I can verify that the Array Controller has the objects in it by NSLogging [arrayController arrangedObjects], and it returns the correct object. Its just that nothing displays in the NSCollectionView.

UPDATE 2: If I log [collectionView content] I get nothing:

2009-10-21 08:02:42.385 CollViewTest[743:a0f] (
)

The problem is probably there.

UPDATE 3: As requested here is the Xcode project:

http://www.mediafire.com/?mjgdzgjjfzw

Its a menubar app, so it has no window. When you build and run the app you'll see a menubar item that says "test", this opens the view that contains the NSCollectionView.

Thanks

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa