如何通过绑定在弹出按钮中选择名字的文本字段中显示用户的姓氏
我有一个字典数组,其中包含两个键 - FirstName 和 LastName 及其值,例如。
名字/姓氏
Steve/ Jobs
Andre/ Agassi
Christiano/ Ronaldo
用户界面由弹出按钮和文本字段组成。
我在弹出按钮中显示用户的名字。我可以使用以下绑定在文本字段中的弹出按钮中显示所选用户的名字:
NSArrayController
Content Array - AppDelegate - myArray
NSPopUpButton
content - Array Controller -arrangedObjects - firstName selected value - AppDelegate - SelectionValue
NSTextField
值 - AppDelegate - SelectionValue
这里 myArray 是声明为 NSArray 的属性,selectionValue 是声明为 AppDelegate 类中声明的 NSString 的属性。
现在我对通过绑定实现这一点不太了解: 文本字段应显示在弹出按钮中选择名字的用户的姓氏。
谁能建议我一些解决方案来实现它,或者是否可以通过绑定?
I have an array of dictionary which contains two keys- firstName and lastName and their values, eg.
firstName/ lastName
Steve/ Jobs
Andre/ Agassi
Christiano/ Ronaldo
User interface consists of a pop up button and a text field.
I am displaying first name of users in pop up button. I am able to show first name of the user selected in pop button in the text field by using following bindings:
NSArrayController
Content Array - AppDelegate - myArray
NSPopUpButton
content - Array Controller - arrangedObjects - firstName
selected value - AppDelegate - selectionValue
NSTextField
Value - AppDelegate - selectionValue
Here myArray is a property declared as NSArray and selectionValue is a property declared as NSString declared in AppDelegate class.
Now I am getting clue less to implement this through bindings:
Text field should show last name of user whose first name is selected in pop up button.
Can anyone suggest me some solution to implement it or is it possible through bindings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其更改为 NSDictionary 类型,而不是将选择值保留为 NSString 类型的属性。
现在绑定的外观如下。
NSPopUpButton
内容 - 数组控制器 -arrangedObjects -firstName
选择值 - AppDelegate -selectionValue -firstName
NSTextField
值 - AppDelegate -selectionValue -lastName
这应该有助于解决您的问题。
Instead of keeping selectionValue as a property of type NSString you can change it to be of type NSDictionary.
So here's how the bindings would look now.
NSPopUpButton
content - Array Controller - arrangedObjects - firstName
selected value - AppDelegate - selectionValue - firstName
NSTextField
Value - AppDelegate - selectionValue - lastName
This should help solve your problem.