PDA

View Full Version : Dynamic UI questions on methodology




dale.albiston
Mar 15, 2007, 08:15 AM
I'm looking to have a dynamic element in the UI of a project, specifically it will be something like an object inspector (it will process config files for an application).

I can do this using a tableview as long as i edit everything as text (it will be stored as text), however what I would like to do is have differing controls for some rows. e.g. if the allowed text is '0' or '1' then using a checkbox makes sense, for slightly longer lists a combo box makes sense. for some just a plain text box works fine.

Question: is it possible to have different cell types in a single table column? and if so how?

I'm sort of assuming I'll need to have a single cell type, which would be a custom control that can appear as one of several child controls but I'm not too sure how to manage this.

searching for cocoa dynamic user interface in google hasn't exactly helped.

another alternative i suppose is to create controls manually in a scrollbox (i.e. drop the table totally), but i'd prefer to use a table if possible.

also: is it possible for table rows to have different row heights? or must they all be the same?

pointers on were to look for this sort of information greatly appreciated, the apple documentation is good on syntax but short on examples...



robbieduncan
Mar 15, 2007, 08:46 AM
Yes you can have different stuff on different rows. You do it using the table view delegate method to alter or switch the cell on the row as it gets drawn.

The method in question is tableView:shouldEditTableColumn:row: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html#//apple_ref/doc/uid/20000118-BCIBJBAG).

Note that this assumes that you have the same cell for each row. If you want to have different cells I'd have thought you could use your own Cell class that calls the appropriate method in the other cell classes when asked to draw etc...

Or you could follow this very short example here (http://www.corbinstreehouse.com/blog/?p=46)

dale.albiston
Mar 15, 2007, 08:57 AM
Yes you can have different stuff on different rows. You do it using the table view delegate method to alter or switch the cell on the row as it gets drawn.

The method in question is tableView:shouldEditTableColumn:row: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html#//apple_ref/doc/uid/20000118-BCIBJBAG).

Note that this assumes that you have the same cell for each row. If you want to have different cells I'd have thought you could use your own Cell class that calls the appropriate method in the other cell classes when asked to draw etc...

Or you could follow this very short example here (http://www.corbinstreehouse.com/blog/?p=46)

I thank you.. this looks like it will actually do what I'm after from a visual point of view, but its looking like I'll be creating a custom cell view to pass much of the handling logic into one place.

Thanks for the links though, most helpful :-)