views:

555

answers:

3

I want to add a subview to the UITableCellView class. However, non of the provided views in the class seem to be able to do exactly what I was looking for.

I basically want to add my own background view, filling the whole cell. However, if I replace the backgroundView, the style from the grouped table view layout isn't displayed anymore. If I add a subview to backgroundView, the subview is not shown at all. If I add a subview to the contentView, I can't draw behind the accessory icon.

What am I missing?

+1  A: 

You might want to take a look at this article:

"Easy custom UITableView Drawing"

In particular:

First: the UITableView does not itself draw anything except the background. To customize the background of a UITableView, all you need to do is set its backgroundColor to [UIColor clearColor] and you can draw your own background in a view behind the UITableView.

Ronnie Liew
That's not exactly what I was looking for. I only want to customise one UITableCellView, not the whole table. The article is suggesting to use custom background images for every cell. That's going to be a pain if I want to support different orientations on both iPad/iPhone...
hanno
+1  A: 

Basically you can't change the backgorund of GroupedTable View.

Try using it with PlainTable.

and add the your backgroung image (of size = cellsize) to cellforRowAtIndex method.

yakub_moriss
I'm going with this idea for now. Not ideal, but the quickest and cleanest solution that I found so far.
hanno
A: 

Simply add the custom view as part of your contentView. Set a unique reuse identifier for that cell, configure it when you create it and from then on simply reset the data components (this is easiest to do if you create a custom cell controller class so that it can track all the parts and use setters/getters for the data).

Huygir