Xcode 7:将数组控制器绑定到单选按钮组 [英] Xcode 7: Binding an array controller to a radio button group

查看:322
本文介绍了Xcode 7:将数组控制器绑定到单选按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一小组对象,用户应该能够使用单选按钮组选择一组对象。对象已绑定到阵列控制器。有没有办法将数组控制器绑定到单选按钮组,以便动态生成其他单选按钮?如果可能,首选IB解决方案。

I have a small set of objects from which the user should be able to select one using a radio button group. The objects are already bound to an array controller. Is there a way to bind that array controller to a radio button group so that additional radio buttons are generated dynamically? If possible, an IB solution is preferred.

示例项目: https://scriptreactor.com/collectionviewtest_radio.zip

目标是能够选择项目a,b,

Goal is to be able to select one of the items "a", "b", "c", and have that selection available in the view controller.

推荐答案

您可以通过基于视图的表中的 NSTableViewCell )和集合中的resentObject 视图( NSCollectionViewItem )。

You can bind the button state through objectValue (NSTableViewCell) in a view-based table, and representedObject in a collection view (NSCollectionViewItem).

如果将 NSArrayController 配置为为这些父视图生成单元格/项目,视图将保持对集合中每个视图的 objectValue resentObject 绑定目标。

If an NSArrayController is configured to generate cells/items for those parent views, the views will maintain the state of the objectValue and representedObject binding targets for each view in the collection.

所以在IB中,你有一个通用子视图,其中有一个单选按钮,你应该能够选择集合视图项,键值resentObject。< whateverKeyPath> 用于绑定单选按钮(如果它在集合视图项中)。或者,如果按钮是基于视图的表的表视图单元的子视图,则可以选择具有 objectValue。< whateverKeyPath> 的键值的Table View Cell。

So in IB, you have one generic subview with a radio button in it, and you should be able to select "Collection View Item" with a keypath of representedObject.<whateverKeyPath> for the binding of the radio button if it's within a collection view item. Or you could select "Table View Cell" with a keypath of objectValue.<whateverKeyPath> if the button is a subview of a table view cell for a view-based table.

尽管可能已经过近期OSX 10.10对 NSCollectionView 的更新,但快速入门指南介绍了如何在集合子视图中配置绑定视图。表视图子视图绑定是类似的,虽然您使用 objectValue 而不是resentObject 作为视图中的属性。

Though it may be dated by recent OSX 10.10 updates to NSCollectionView, the quick start guide has good illustrations on how to configure bindings within subviews of collection views. Table view subview bindings are similar, though you use objectValue rather than representedObject as the property within the view.

这篇关于Xcode 7:将数组控制器绑定到单选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆