How do you initialize a NSCollectionViewItem?

[亡魂溺海] 提交于 2019-12-06 05:49:07

I found this documentation - NSCollectionViewItem class

What I found there shows setting a reference like so:

Setting the Represented Object

    – representedObject Available in Mac OS X v10.5 through Mac OS X v10.5
    – setRepresentedObject: Available in Mac OS X v10.5 through Mac OS X v10.5 

Your sample: -(void)setSelected:(BOOL)flag

I don't know the language but is BOOL an id?

setRepresentedObject:

Sets the receiver’s represented object to the specified model object. (Available in Mac OS X v10.5 through Mac OS X v10.5.) - (void)setRepresentedObject:(id)object Parameters

object

The receiver’s model object.

Availability

Available in Mac OS X v10.5 through Mac OS X v10.5.

Declared In NSCollectionView.h

Note: I did see this on the documentation:

Important: In Mac OS X v10.5, the superclass of the NSCollectionViewItem class was NSObject. In Mac OS X v10.6 and later, NSCollectionViewItem is now a subclass of NSViewController. This change was made to improve how the view is replicated within the NSCollectionView. NSCollectionViewItem remains binary compatible with the previous implementation and unarchiving is correctly handled.

So, if you are used to working with an older API, there may have been some changes since you last did this ...???

I cannot link the view back to the NSCollectionViewItem subclass in Interface Builder.

You should bind elements in your custom view to the file’s owner (whose class should be CollectionViewItem) represented object. For instance, your image view would be bound to the file’s owner with the model key path being representedObject.imageSource.

Is there an init method I can use with my NSCollectionViewItem in order to perform initialization operations?

NSCollectionViewItem is a subclass of NSViewController. As such, you can override -loadView to perform custom initialisation. For instance,

@implementation CollectionViewItem
…
- (void)loadView {
    [super loadView];
    self.someProperty = someDefaultValue;
}
…
@end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!