Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HiRez

macrumors 603
Original poster
Jan 6, 2004
6,250
2,576
Western US
Hi, I'm getting a strange error trying to bind objects into an NSPopUpButton. In Interface Builder, I have an NSArrayController bound an array in my document. I'm binding the contentObjects of my popup to the array controller, and the contentValues to a string key within the objects in the array. It all works well except for one thing:

kvo_error.jpg

The two top objects are the ones in the array, and they're correct. The goofy one on the bottom is I guess being inserted by the runtime initially, and I have no idea why. RBAudioDevice is the class of the objects in the bound content array. Now, when I select one of the other two normal items, the strange one goes away and never returns. After that, it works perfectly, but I can't get it to stop that one item from appearing when the app launches. "Automatically prepares content" does not make a difference, nor do any of the other settings. Any ideas? I've never seen this before.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
I have used bindings for this before and IIRC you connect contentObjects to the array controller as you've done and use the key field to select the appropriate key in the object. I don't think you need to connect contentValues as well. The currently selected object is specified using one of the 'selected...' bindings. I usually use selectedIndex.

This is all from memory so I could be mistaken...
 

HiRez

macrumors 603
Original poster
Jan 6, 2004
6,250
2,576
Western US
caveman_uk said:
I don't think you need to connect contentValues as well.
I think I had to do that because if you don't, it invokes description: on your object for the text it places in the popup (the item titles) and I didn't want that behavior (I needed a certain other string). Anyway, I may have figured it out. I think it has something to do with a situation where the KVO system gets to the popup before your code can populate it (it queries the array before it's initialized), and it inserts that dummy object. It's hard to tell since I have no way of knowing what the bindings runtime system is doing behind the back of my code.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
I do have to admit whilst I think the bindings systems is very useful, it isn't the panacea some people like to make out. It has a whole set of its own gotchas and if you want to do something a bit special (such as custom cells in tableviews) you're back writing datasource methods.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.