0

I am very new to Cocoa and I am developing one normal Cocoa desktop application in Xcode 4.5. I have a requirement to display values in NSComboBox and I have to retrieve from NSComboBox, but restriction is that I should not do bindings to IBOutlet.

If we want we need any use of Array controllers we can use NSArrayControllers but not with IBOutlets.

Will any one suggest me how to perform this task without using IBOutlets.

I don't want to use IBOutlets because of:

  1. It reduces the code: Assume we have 15 text fields in UI, so you need to have 15 IBOutlets (If you are working on small project you can have it but when we implement bigger size project, you may end up creating tons of IBOutlets, which does nothing other then helping to access value from the text fields.

    If you use binding rather than IBOutlet, handling UI is easy, Let's assume you have one table with linked arrayController. When array is modified which you linked with array Controller, automatically changes will reflect in the tableView, you no need bother about updating the tabelView, if we use IBOutlet, we have to scratch out head to update the content. Whenever data is modified which we display in tableView.

  2. Makes developer's life easy: If we use bindings, Any changes happened in binding object immediately reflects in the UI, we need not worry about updating of UI.

  3. Easy-to-understand code: If we use IBOutlets unnecessarily we end up with writing code to handle views, updating views and etc, in case we use bindings automatically it updates.

According to me. Good practice if we use bindings.

IBOutlets simply increase length of code.

Thank you in advance...

NSGod
  • 22,699
  • 3
  • 58
  • 66
user2118335
  • 1
  • 1
  • 5

2 Answers2

1

Steps how to bind:

  1. Draw a NSComboBox and a NSTextField that would be bind to combo box.

  2. In combo box add items from Interface Builder.

  3. Select Combo box. Hold Ctrl and drag to NStextField/label and select takeStringValueFrom.

That's it!!!

Now you can build & run and check the selection changes in combo box is visible in textfield as well.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • But to do these we have to hide that label or textfield from the user to display, isn't there any other way to get solution for my problem? – user2118335 Mar 04 '13 at 11:13
  • My requirement is, I have 2 combo boxes. Based on the first combo box values the second combo's values should get loaded. – user2118335 Mar 04 '13 at 11:27
0

You'll need to set up your combo boxes delegate to handle comboBoxSelectionDidChange method.

http://www.cocoabuilder.com/archive/cocoa/221619-detecting-when-nscombobox-text-changed-by-list.html

basawyer
  • 36
  • 2