「ImageCollectionViewItem」と呼ばれるアイテムを表示するNSCollectionViewがあります。アイテムをカバーするNSViewだけを持つImageCollectionViewItem.xibファイルがあります。私は、そのビューにあるものを動的に変更できるようにしたいが、参照しようとすると、それはゼロになる。私はすでに次のような質問にチェック:outlets in UIViewController nil in viewdidloadを、それは私の問題ではありません、私はそれをリンクされて、私はここで黒丸NSCollectionViewItemにはitemForRepresentedObjectAtIndexPathにnilコンセントがありません
を持っているのViewController拡張です:
extension ViewController : NSCollectionViewDataSource {
func collectionView(collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return titles.count
}
func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItemWithIdentifier("ImageCollectionViewItem", forIndexPath: indexPath) as! ImageCollectionViewItem
//This is what is nil:
let thisView = item.iconView
return item
}
}
そして、ここではImageViewCollectionItemコードは
ですclass ImageCollectionViewItem: NSCollectionViewItem {
@IBOutlet weak var iconView: NSView!
var numItem: Int?
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.whiteColor().CGColor
}
}
私は、しかし、同じ問題を持っているし、あなたのソリューションユージンを試してみました私はまだ私のimageViewのためのnilを取得します。 myImageViewという新しいコンセントを作成しようとしましたが、それもnilを返します。 –
サンプルプロジェクトを共有できますか?私はそれが少し見落とされていると確信しています。時には私にも起こります。 –