On Mar 19, 2010, at 3:21 PM, H. Miersch wrote:

> just had another surprise: i inserted NSLogs into the method that initializes 
> the array and into -numberOfItemsInComboBox, trying to see the contents of my 
> array and find out why -numberOfItemsInComboBox returns zero. the surprise 
> was that -numberOfItemsInComboBox is called BEFORE the method that 
> initializes the array. then i commented the line that sends 
> -selectItemAtIndex to the combobox, and the combobox worked normally. 
> 
> now the question is, why is -numberOfItemsInComboBox called first when the 
> first call in awakeFromNib is to the initialisation method? weird...
> 
> -awakeFromNib {
>       init array;
>       [combobox selectItemAtIndex:0];   // if this line is turned into a 
> comment, it works normally.
>       [combobox2 selectItemAtIndex:2];
>       [combobox3 selectItemAtIndex:0];
>       register for notifications from combobox;
> }

You are setting up your array in your -awakeFromNib.

You cannot control (or know) the order in which -awakeFromNib will be sent to 
objects in your nib. The combo box may be awoken long before you.

But more to the point, your contract with the combo box as its data source is 
that you will send it -noteNumberOfItemsChanged or -reloadData whenever you 
change the data in the data source.

You became the data source for the combo box during nib unarchiving, changed 
the number of items in the model after nib unarchiving, and didn’t inform the 
combo box about that change. Sending the combo box the appropriate method after 
initializing your data source should fix the problem.

Jim

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to