in Xcode 3.1.2 I used to load the nib of the NSCollectionViewItem
in my subclass of NSCollectionViewItem
like this:
-(id)copyWithZone:(NSZone *)zone
{
id result = [super copyWithZone:zone];
[NSBundle loadNibNamed:@"PersonView" owner:result];
return result;
}
In Xcode 3.2 under 10.6 the same method doesn't yield to an error, but it doesn't load the view in the NSCollectionView
either.
Is there something else that needs to be done to make the view show up?
Or is there even a better way of doing this that comes with the change of NSCollectionItem
's superclass to NSViewController
?
After all, overriding copyWithZone
to achieve this standard functionality always seemed like a hack to me. I think one should be able to specify the nib that's supposed to be used in IB, but it seems like Apple doesn't think so.
I did have a look at the example that is available in the documentation, but there the NSCollectionViewItem
is instantiated programmatically using initWithNibName
, but I would like to create it in the IB.
UPDATE:
I did what kperryua suggested, but now I can't access outlets from the NSCollectionViewItem
. Here's what I'm trying to do:
- (void)setRepresentedObject:(id)object {
if (object) {
[labelName setValue:[object name]];
}
}
I binded the label name to the file owner which is my NSCollectionViewItem
. That used to work perfectly in 10.5, but now the outlet is not assigned(I checked that with GDB).
image showing the bindings http://img21.imageshack.us/img21/671/picya.png
UPDATE 2:
I also binded the NSCollectionView
's itemPrototype
to my subclass of NSCollectionViewItem
(PersonController).
image showing bindings http://img503.imageshack.us/img503/4672/pic2d.png
Now both the File's Owner
of the PersonView.nib
and the itemPrototype
of the NSCollectionView
point to my subclass.
image showing console output http://img340.imageshack.us/img340/6184/pic3.png
As you can see in the screenshot the item are displayed, but the text of the label can't be changed as the outlet labelName
isn't accessible.
I also logged the name that I'm trying to set to make sure it isn't 'Name'.
What needs to be done to change the label's value?
Any help would be appreciated.
Yes, Snow Leopard makes this much easier. In IB, click on the NSCollectionViewItem and set the nib name and bundle name (just leave it blank for the main bundle). In your PersonView nib, make the NSCollectionViewItem the File's Owner and connect the -view outlet to a view in that nib. (It looks like you might have this set up like that already in that nib.) Everything else should be automatic, and overriding copyWithZone: shouldn't be necessary.