indentationLevel property doesn't appear to do anything?

indentationLevel property doesn't appear to do anything?

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?

Creating a PHP Webservice with binary-encoded parameters?


Is there an iPhone SDK API for twitter? [closed]
indentationLevel and indentationWidth affect the positioning of the standard items textLabel, detailTextLabel, and imageView.

iPhone Safari: Scroll a list inside a html container
They do not affect the origin of contentView's frame..
iphone: making a new UIImage from data from an XML document
If you are not using textLabel, etc.

What's the best way of learning iPhone programming when coming from Java?
(perhaps because targeting iPhone OS 2), you need to handle the indentation manually, as the previous answer shows..
-didSelectRowAtIndexPath: not being called

Why do I have to clean up memory if I have an IBOutlet with “retain”, but not when I have one with “assign”?

If my property has no setter (readonly), is it true that UIKit retains the value if it's not NSNumber or NSValue?


This appears to be a bug in iOS 7 if you are not using custom cells.. Setting either indentationLevel or indentationWidth within tableView:cellForRowAtIndexPath: has no effect on the cell's layout when it is time to display it.. For example, consider the following code:.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];      BOOL isIndented = indexPath.row % 2;      cell.textLabel.text = isIndented ? @"Indented" : @"Not indented";     cell.indentationLevel = isIndented; } 
I don't have enough reputation to post screenshots, but the result is different between iOS 6 and iOS 7.

This is using Xcode 5 and the iOS 7 SDK..


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

in .
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {         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)];          }    } 


I ran into a similar issue with my app.

I had a UITableView that was NOT using custom cells.

I was using a UITableViewCell with a Basic style.

In my - (UITableViewCell *)tableView: cellForRowAtIndexPath: delegate method I set the cell's indentationWidth and indentationLevel.

They did nothing.

I even tried modifying the - (NSInteger)tableView: indentationLevelForRowAtIndexPath: delegate method.

Nothing.. What did eventually work was going to the storyboard and modifying the attributes of the Table View Cell itself.

Once I set the Indentation Width there, I started getting proper indentation.

The indentationLevel property started to work.

Even the - (NSInteger)tableView: indentationLevelForRowAtIndexPath: was useful.. Basically, it looks like the indentationWidth property is ignored in favour of the "Indentation Width" in the storyboard.. This was with Xcode 5.0.2 targeting iOS 7..


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)?.


I know this question is 4 years old, but if you are already using a custom subclass of UITableViewCell, and you're already adding your views as subviews of contentView make sure you're not overriding layoutSubviews in your cell.

If you are, you'll need to adjust the bounds/center or frame of the contentView manually, in layoutSubviews..

50 out of 100 based on 55 user ratings 280 reviews