views:

962

answers:

2

Hi, I'm new to Objective-C and iPhone coding and was hoping someone could help me.

Basically I want a scrollable table that displays a name and a quantity of that item. For example: Apples.........2
Oranges......4
Bananas......5

I want the name to be left-justified and the number to be right-justified.

Is there any way to do this with a UITableView or will I need to extend UIScrollView?

Thanks in advance.

+3  A: 

Set cell.text to "Apples". Then create an new UILabel view with the text "2" and assigned it to cell.accessoryView.

Text is always on the left, and accessory views are always on the right. Optionally a UIImage in cell.image will be displayed to the left of the cell text if you choose to add one.

If you have a cell layout more complicated than that you have to add subviews to your cell manually.

Squeegy
I think "a cell layout core complicated" was supposed to be "a cell layout MORE complicated" :)
Adam Douglass
+1  A: 

One not too difficult option is to subclass UITableViewCell with one label for the text and one label for the number, then just set the label values.

If you want the ... that you've shown then you could probably use a standard UITableViewCell and write some code to feed the cell text that has been pre-modified to fit in the space alloted.

pat