How to show last name of user in text field whose first name is selected in pop button, through bindings

StackOverflow https://stackoverflow.com/questions/9128078

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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top