Binding to NSCollectionViewItem crashes Xcode

吃可爱长大的小学妹 提交于 2019-12-10 10:13:20

问题


Using XCode 4.1 I've come across a crash whenever I try to use a CollectionView.

These are the steps I'm doing:

  1. From a new project, edit the MainMenu.nib file.
  2. Add an NSCollectionView to the window, which also adds a Collection View Item, and a new View In the new View
  3. Add a control like an NSTextField
  4. Select the control, and switch the inspector to the binding pane.
  5. Attempt to bind something to the Collection View Item. Once the Collection View Item is selected in the dropdown menu, an "Internal Error" dialog appears. Attempting to continue from this dialog makes the binding pane disappear until you restart XCode

Does this happen for anyone else or is it just something I'm coming across? Is there a way to work around it to allow me to bind to the Collection View Item (I want ultimately to bind to the representedObject value) either in XCode or in code.

I attempted to create a custom NSCollectionViewItem subclass that uses a separate nib file and set that as the itemPrototype of the NSCollectionView but things went very wrong then.


回答1:


I found that splitting the collection view item view into its own XIB and then rewiring the connections so that the collection view item prototype loads the new XIB will allow for you to create the bindings in interface builder without it crashing. I followed these steps...

  1. Delete the collection view item view from the default xib.
  2. Create a new view and XIB inheriting from NSCollectionViewItem.
  3. Create your collection view item in the new view.
  4. Bind the fields to the files owner of the new view.
  5. Back in the collection view xib, update the properties of collection view item to load the bin name of the new xib.

I'm not sure that it's quicker than doing it programmatically, but it does allow you to manage the bindings without writing code. I've got a few apps working this way now.




回答2:


I've found a temporary work around:

Select the "Collection View Item" and under the "Attributes Inspector" → "View Controller" settings, set "Nib Name" to "MainMenu".

Once you've done this, it won't crash, and you can set the bindings. Be sure to clear the "Nib Name" setting when building your app.




回答3:


Yup, I can confirm this bug too, even on Interface Builder 3.

The only workaround is to do the binding programmatically:

[textField bind:@"value" toObject:collectionViewItem withKeyPath:@"representedObject.foo" options:nil];


来源:https://stackoverflow.com/questions/6866798/binding-to-nscollectionviewitem-crashes-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!