Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 817
JoBu1324 Avatar asked Aug 20 '09 01:08

JoBu1324


2 Answers

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.

like image 190
Justin Bur Avatar answered Oct 16 '22 22:10

Justin Bur


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.

like image 34
idzski Avatar answered Oct 16 '22 20:10

idzski