On Aug 10, 2009, at 11:04, Brian Carmalt wrote:

Let's say I want the combo box to provide the user with auto completion on the names of categories in the array controller, and if the user types in a category name that does not exist, then they will be automatically prompted to create the category. This will not work with a popup button. Will this work? or are there known pitfalls I should look out for?

I should create a new array controller in my NewObjectSheet context and set it up to use the documents MOC and bind my combo box to this new array controller, that is if I can use the NSComboBox like I described above.

Nope, it's not going to work. Suppose your document has 4 existing categories: "cheese", "fruit", "meat", "bread". Suppose you bind an array controller to the array of categories, and you bind a combo box's popup list to arrayController.arrangedObjects and you bind the combo box's value to arrayController.selection.name.

Now your sheet will open, and the combo box will show one of the categories -- let's say "fruit". If you choose a different category -- let's say "cheese" -- from the popup list, you'll actually change the category name. So the document will now have 4 categories named: "cheese", "cheese", "meat", "bread". I'm pretty sure that's not what you want.

You don't want to bind the combo box to arrayController.selection.name. If you really want to use a combo box, you'd have to bind it to a "temporary" string property of your sheet window controller. Then you'd have quite a bit of extra work to do. You'd have to prefill this text field with the correct category string at initialization. When ending the sheet, you'd have to examine the category string, decide if it was one of the standard ones, and create a new one if not. Or perhaps you'd do this when a new string was entered, and wait till the sheet ended. Plus you may need to use NSComboBox methods to determine which existing category, if any, was chosen from the popup list. Plus you might need some validation code. Plus you might need some string formatting code (capitalizing or uncapitalizing entered category names so that the appearance of all of them is consistent). It's doable, but it's a certain amount of work, because ...

"A combo box is a kind of text field, not a kind of menu."

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to