views:

233

answers:

2

Hi,

I want to have a tableview create rows that look like this:

value1      item1     container1  
value10     item10    container10  
value100    item100   container100  
value2      item2     container2  

What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.

I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.

A: 

You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)

Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.

There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.

JoostK
I noticed that the tutorial is pre-SDK 3.0. Is it still relevant or has it been deprecated? I am starting to look out for this. If it is still valid, I have no problem with drawing my own cell. And thx for your other answer as well.
Wes
You can safely use it under 3.0, it's done the same way.
JoostK
A: 

It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.

Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.

You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.

TechZen