4

I have an NSCombobox in my app and I have a datasource set up for it.

 IBOutlet NSComboBox *comboBox;

I also specify at some point in my program:

[comboBox reloadData];

My thought would be that after this call, I should get calls to these methods as long as I remembered to set the datasource of the combo box (which i did):

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox

But I don't. Is this not how combo boxes work?

JPC
  • 8,096
  • 22
  • 77
  • 110
  • It looks like they can operate using a data source or an internal list. When you first populate the combo box, are those methods called? – paulmelnikow Aug 20 '11 at 03:17
  • My understanding of how a data source works is, if in IB, I link the datasource outlet from the combo box to my controller class, then in order to populate the combo box it should call those datasource methods but they never get called. – JPC Aug 20 '11 at 03:18
  • I don't use an internal list, just the data source – JPC Aug 20 '11 at 03:19
  • It sounds like you're saying they aren't getting called at all, though: neither before nor after a call to `reloadData`. (Provided you can set up whatever structures the data source methods require before the first time the combo draws, there's no need to call `reloadData` unless the data changes.) – paulmelnikow Aug 20 '11 at 03:22
  • 1
    Under **Combo Box** in IB, is **Uses Data Source** selected? – paulmelnikow Aug 20 '11 at 03:23
  • It is now...I didn't know there was a checkbox there! All is good. Thanks! – JPC Aug 20 '11 at 03:33

1 Answers1

3

If you're using a combo box with a data source, and provided you can set up whatever structures the data source methods require before the combo first draws, you only need to call reloadData if the data subsequently changes.

If the data source methods aren't being called at all – either before or after a call to reloadData – make sure the combo box is configured to use a data source. In the nib, under Combo Box, select Uses Data Source, or call [comboBox setUsesDataSource:YES] in code.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114