views:

47

answers:

1

I have a table view where cells can display a variable amount of information. For example, the first cell could display 2 labels, the next cell 5 labels, and the third cell could display 1 label. The cell contents are stored in managed objects.

I would like to make this data driven, where I have a plist to configure the cells. I'm thinking that I can create a layout manager that reads in the config data and can intelligently determine how to display the labels.

Is there a better way to do this with UIKit? I realize that ultimately I could use Core Text to do the text rendering, but I would like for that to be an implementation detail. For starters I'd be happy with just have UILabels that are dynamically setup.

EDIT:

One side effect of making this driven from a config file is that I could update these configurations after the app has been deployed. I might consider generated xib files for download as well, but ideally I'd like to only delivery binary plists.

+1  A: 

If all you're doing is configuring a single kind of table view cell with a variable number of labels, it seems like that's just a one-off piece of code for laying out the right number of labels. I can't quite tell from your question what your experience level with doing programmatic layout it; if you're new to doing UI outside of IB, let us know.

Speaking to the more varsity idea of a "layout manager", do consider that the NIB/XIB system is effectively a data-driven layout engine itself. If you're thinking about something that's generic enough to specify explicit layouts and properties of views, consider that that's what XIB files basically are-- a schematized XML layout. See the command line tool ibtool's documentation (manpage here) to learn more about how you can manipulate them.

If your layout needs are specific enough to your app but too general to handle with a set of fixed XIBs, then consider a lightweight manager like you describe. But I would think hard before going off and building something super-generic. The equivalent of Zawinski's law here is that any layout manager will eventually end up incorporating more and more of the XIB functionality.

quixoto
Thanks for the response! I'm fairly experienced with iOS development and know my way around AppKit as well. I'll have a look at ibtool and see if there is something in there to help me out. Thanks!
logancautrell