views:

37

answers:

1

I have an NSComboBox and I was wondering if there is an easy way to convert it to an ordinary NSTextField? Considering NSCombBox is a subclass of NSTextField, I would think there is an easy way to turn this on/off but I can't figure it out.

A: 

They are two separate controls. You'll just have to swap one out for the other. If you're looking to do this in Interface Builder at design time, it's mind-numbingly simple. If you're looking to do this in code, it's not overly difficult (especially if you already have both controls created and configured somewhere in your XIB, like an off-screen view).

It might help to describe what you're trying to accomplish (ie, why you want to swap the controls). It's difficult to give a succinct answer without more information about your goals.

Joshua Nozzi
I had data that could be in the form of an array or string so I needed to determine if I should create an NSTextField or an NSComboBox. By default the my IBOutlet was an NSTextField. Basically I had to check my data object that I used to set the field isKindOfClass:[NSString class]. If it was an NSString set the data. If not, copy the NSTextField's bounds and any other important params, remove from NSTextField from superview, initialize an NSComboBox, set the params (that we copied from NSTextField), set the data and finally set the target and actions.
macmichael01
Why can't it just always be represented as an array of strings, even if there's only one string? I'm sure it's not too difficult to prevent the menu popping up in that case. Have you considered something like that?
Joshua Nozzi