问题
Using XCode 4.1 I've come across a crash whenever I try to use a CollectionView.
These are the steps I'm doing:
- From a new project, edit the MainMenu.nib file.
- Add an NSCollectionView to the window, which also adds a Collection View Item, and a new View In the new View
- Add a control like an NSTextField
- Select the control, and switch the inspector to the binding pane.
- 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...
- Delete the collection view item view from the default xib.
- Create a new view and XIB inheriting from NSCollectionViewItem.
- Create your collection view item in the new view.
- Bind the fields to the files owner of the new view.
- 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