문제

I am new to Mac development. I want to get the value selected from a combo box and assign it to the text of a label in a Mac app using Objective-C. How can I do this?

도움이 되었습니까?

해결책

Following gives the selected value:

[yourComboBox objectValueOfSelectedItem] returns id. Have a try with following, if in case you may require to type cast it to NSString.

[self.yourLabelOutlet setStringValue:[yourComboBox objectValueOfSelectedItem]];

*Not checked, but something similar to this

EDIT:

Find a Sample Project.

다른 팁

The accepted answer only works when your NSComboBox does not use its own dataSource

When using your own dataSource for your NSComboBox you should approach it like this:

[yourDataSourceArray objectAtIndex:[yourComboBox indexOfSelectedItem]]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top