pierocampanelli
pierocampanelli

Reputation: 948

Creating custom combination of widget in Cocoa

I have seen that in Cocoa I can create a custom view using drawing primitives which allows me to draw what I like but at a very low level. Instead I'd like to create custom widgets using a combination of existing controls. For example:

How can I approach this problem ?

Secondly a typical cocoa developer uses external controls? Is there a repository or a list of interesting external custom controls (commercial or free) ?

Upvotes: 2

Views: 655

Answers (1)

Amy Worrall
Amy Worrall

Reputation: 16337

I'd like to create a table with images and combobox in cells

There already exists NSImageCell and NSComboBoxCell. Are you sure you need to do anything different?

If the problem is that you want an image and a combo box in the same cell, you will have to subclass NSCell. Currently table views can only contain cells, not views, which makes your life harder (as understanding how cell drawing works is more difficult). That will change in Lion, however, so if you can wait until then, this will become easier!

I'd like to create a custom widget wich is a combination of several (for example a list, a button and combobox)

How is your custom widget different to just placing those three things in the same view?

You could write your own NSView subclass. When it's created, it should create a list, a button and a combobox and add them as subviews to itself. Your NSView subclass should handle the logic of keeping them in sync or doing whatever it is you want them to do. Then, to use this combination control in Interface Builder, you place a Custom View and set its class (rightmost tab of the inspector) to your NSView subclass.

BTW, on a tangent, are you sure you mean combobox? Loads of people coming from Windows get this one wrong. A combobox is a combination of a menu and a text field: it allows the user to enter custom text that is not in the menu. If you just want a dropdown menu of choices (and the user can't enter a custom one), you use an NSPopupButton.

Secondly a typical cocoa developer uses external controls?

Yes, sometimes. Things like BWToolkit can be very useful. There's a lot more that are just floating around mailing lists as code snippets, rather than being cleaned up and put in a library. Search for what you need to do!

Upvotes: 3

Related Questions