これは簡単な作業だと思いますが、機能させることができないようです。カスタム アイテムを含む NSCollectionView を作成しようとしています。別の NSImageView をアイテムのカスタム ビューに追加し、この追加の NSImageView に接続されたカスタム アウトレットを追加するために、このビューをサブクラス化しました。
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object
この NSImageView を削除する必要がある場合があるため、オーバーライドしています。
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
CustomItem *theItem = (CustomItem *)[super newItemForRepresentedObject: object];
...
if (I need to remove that NSImageView) {
[[theItem additionalImageView] removeFromSuperview];
}
return theItem;
}
とにかく、追加のImageViewのよう(nil)
です。スーパーメソッドはカスタムアウトレットを持たないデフォルトの NSCollectionViewItem を返すため、これはある程度明白です。
ここで何をするのが最善ですか?メソッドについて何か読んcopy
で、試してみました:
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
CustomItem *theItem = [(CustomItem *)[super itemPrototype] copy]; // Here is the change
...
if (I need to remove that NSImageView) {
[[theItem additionalImageView] removeFromSuperview];
}
return theItem;
}
しかし、これはうまくいきません。では、カスタム NSCollectionViewItem を使用するときにカスタム アウトレットを保持する方法はありますか?
どんな助けでも大歓迎です。ありがとうございました!