简体   繁体   English

绑定到NSCollectionViewItem会导致Xcode崩溃

[英]Binding to NSCollectionViewItem crashes Xcode

Using XCode 4.1 I've come across a crash whenever I try to use a CollectionView. 使用XCode 4.1每当我尝试使用CollectionView时,我都会遇到崩溃。

These are the steps I'm doing: 这些是我正在做的步骤:

  1. From a new project, edit the MainMenu.nib file. 从新项目中,编辑MainMenu.nib文件。
  2. Add an NSCollectionView to the window, which also adds a Collection View Item, and a new View In the new View 将NSCollectionView添加到窗口,该窗口还添加了Collection View Item和新视图
  3. Add a control like an NSTextField 像NSTextField一样添加一个控件
  4. Select the control, and switch the inspector to the binding pane. 选择控件,然后将检查器切换到绑定窗格。
  5. Attempt to bind something to the Collection View Item. 尝试将某些内容绑定到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 尝试从此对话框继续使绑定窗格消失,直到您重新启动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. 有没有办法解决它,以允许我绑定到集合视图项(我希望最终绑定到representObject值)在XCode或代码中。

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. 我试图创建一个自定义的NSCollectionViewItem子类,它使用一个单独的nib文件,并将其设置为NSCollectionView的itemPrototype,但事情却非常错误。

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. 我发现将集合视图项视图拆分为自己的XIB,然后重新连接连接以便集合视图项原型加载新的XIB将允许您在界面构建器中创建绑定而不会崩溃。 I followed these steps... 我按照这些步骤......

  1. Delete the collection view item view from the default xib. 从默认的xib中删除集合视图项视图。
  2. Create a new view and XIB inheriting from NSCollectionViewItem. 创建一个新视图和从NSCollectionViewItem继承的XIB。
  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. 回到集合视图xib,更新集合视图项的属性以加载新xib的bin名称。

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. 我现在有一些这样的应用程序。

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". 选择“Collection View Item”并在“Attributes Inspector”→“View Controller”设置下,将“Nib Name”设置为“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. 在构建应用程序时,请务必清除“笔尖名称”设置。

Yup, I can confirm this bug too, even on Interface Builder 3. 是的,即使在Interface Builder 3上,我也可以确认这个错误。

The only workaround is to do the binding programmatically: 唯一的解决方法是以编程方式进行绑定:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM