views:

124

answers:

3

I'm have a number rows I'm inserting into a table using -insertRowsAtIndexPaths:withRowAnimation, and I would like the rows to be indented from the left to distinguish them from the rest of the cells. The indentationLevel property of UITableViewCell looks like it's exactly what I need, but it doesn't seem to do anything. Here's the code I'm using to set the indentation level (dot syntax doesn't make a difference):

[cell setIndentationWidth:10];
[cell setIndentationLevel:1];

Is indentationLevel what I want, or should I be looking elsewhere?

A: 

Everything I've read suggests that's how you're supposed to do it. Make sure that you aren't creating a new cell with the same pointer later on in the code (after you set the indentation, but before it gets drawn). Have you tried setting the indentation to something larger that would be more noticeable on the screen (say, 100px instead of 10)?

Cinder6
When you say pointer, you aren't referring to the identifier, are you? My cells are all objects from the same class, so I imagine they would all be pointers to the same object. My cell identifier, however, is based on the full indexPath, and is therefore unique for each cell. Still no joy for indenting, though.
JoBu1324
I've confirmed that the indentation level and width are being set in the cell before the cell is returned to the OS for display. What could be going wrong?
JoBu1324
A: 

You may be over-riding its implementation in your cells. in

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

try:

    if (cell == nil) { 
 cell = (UITableViewCell*)[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellType01"] autorelease]; 
 [cell setIndentationLevel:indexPath.row];
 [cell setIndentationWidth:10];
 cell.selectionStyle = UITableViewCellSelectionStyleNone;
 // Tag the view 
 [[[cell subviews] objectAtIndex:0] setTag:111]; 
 UILabel* labelView = [[UILabel alloc] initWithFrame: CGRectMake(cell.indentationLevel*cell.indentationWidth, 0, 300, 20)];

}

JDPearlman
A: 

indentationLevel and indentationWidth affect the positioning of the standard items textLabel, detailTextLabel, and imageView. They do not affect the origin of contentView's frame.

If you are not using textLabel, etc. (perhaps because targeting iPhone OS 2), you need to handle the indentation manually, as the previous answer shows.

Justin Bur