Cocoa NSCollectionView不显示任何内容
我试着遵循以下指南: 在集合视图项中使用NSImageView 没有显示任何内容,如果我使用图像设置图像,或者通过代码设置数组,也不会显示任何内容 所以我试着用编程的方式,使用Cocoa NSCollectionView不显示任何内容,cocoa,cocoa-bindings,nscollectionview,kvc,nscollectionviewitem,Cocoa,Cocoa Bindings,Nscollectionview,Kvc,Nscollectionviewitem,我试着遵循以下指南: 在集合视图项中使用NSImageView 没有显示任何内容,如果我使用图像设置图像,或者通过代码设置数组,也不会显示任何内容 所以我试着用编程的方式,使用 func representedObject(representedObject: AnyObject) { super.representedObject = representedObject photoImageView.image = (representedObject as! NSImage
func representedObject(representedObject: AnyObject)
{
super.representedObject = representedObject
photoImageView.image = (representedObject as! NSImage)
println("\(representedObject)")
}
在集合视图项中(子类化)
如果我没有对集合视图项进行子类化,Xcode会告诉我没有原型集,如果我对它进行子类化,它会告诉我“无法加载nibName”。。。(它位于具有正确标识集的故事板中)
我无法使用此集合视图:-(
无论如何,我喜欢绑定…因此我希望通过绑定获得正确的结果。。
我在链接处反复检查了文档中的每一段,一切似乎都很好。主要区别在于文档使用了应用程序委托,我使用的是视图控制器
我在swift中翻译了KVC方法,我认为它们是正确的,因为我知道它们已被调用。它们如下:
func insertObject(p: ClientPhoto, inClientPhotoArrayAtIndex index: Int) {
images.insertObject(p, atIndex: index)
}
func removeObjectFromClientPhotoArrayAtIndex(index: Int) {
images.removeObjectAtIndex(index)
}
func setClientPhotoArray(a: NSMutableArray) {
images = a
}
func clientPhotoArray() -> NSArray {
return images
}
它们基本上有两种使用NSCollectionView的方法。一种是设置
itemPrototype
属性,另一种是覆盖newItemForRepresentedObject
。覆盖方法更灵活,优点是您可以使用下面的技术在情节提要和所有outle中创建nscollectionviewitemts将正确设置。以下是我如何使用它的示例:
class TagsCollectionView: NSCollectionView {
// ...
override func newItemForRepresentedObject(object: AnyObject!) -> NSCollectionViewItem! {
let viewItem = MainStoryboard.instantiateControllerWithIdentifier("tagCollectionViewItem") as! TagCollectionViewItem
viewItem.representedObject = object
return viewItem
}
非常感谢,现在我可以用它了:-)我想用绑定太好了。您可以将我给出的示例与绑定一起使用。什么不适合你?对。我以为是,或者代码,或者绑定:p我必须试试:-)谢谢