views:

397

answers:

3

I need to display a bunch of UITableViewCell in my iPhone application. Sample look below. I know how I can enable accessory view and image to UITableView cell but the problem is that I need to add a star rating as visible on the screen. There's no fancy logic behind it, it will just be few images that will be either enabled or disabled.

I though that I could create a custom UITableViewCell in NIB but how would I use it in cellForRowAtIndexPath method. If it was just one custom cell I'd just provide an outlet for it and hook it with a property and use it there. But since it would be used multiple times I think I'll need to clone it or copy somehow.

What is the simpliest way of adding such stuff to UITableViewCell?

alt text

A: 

I think you may find everything you need here : http://github.com/eisernWolf/TouchCustoms

Either have a look at the code to have an idea of the code you need to use or just implement directly their source code into your project (do not forget to read carefully the license ;))

But in my opinion, it should be fairly easy to make your own custom rating system :

  1. Make a star icon - one empty, one plain
  2. Create UIButtons with relevant icons
  3. Make sure to implement relevant touch events

Okay, that's a summary :D but it shouldn't take too much time to build ;)

gotye
That's not the problem in my case. The problem is how to populate `UITableView` with several custom controls which share the same "template" from NIB.
RaYell
+1  A: 

This Matt Gallagher post helped me a ton when dealing with custom TableView cells http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html.

Summary 1) Do not subclass UITableViewCell 2) In the cellForRowAtIndexPath method, layout your custom subviews on top of the dequeued UITableViewCell.

To add a star just use a UIButton with the default image of a unhighlighted star and a selected image of a highlighted star.

A: 

Maybe my FavStarControl is what you need? ;)

Jasarien
Not really :D I'm not looking for a rating system. I just want to print rating when displaying table view cells. I don't need them to be interactive or anything. Just an image in the background or so.
RaYell
In that case, just have 5 images, each representing what 1/5 stars 2/5 stars would look like etc, and just use that?
Jasarien