1

I have two types of UITableViewCell on top of each other. The first one is UITableViewCellAccessoryDisclosureIndicator and the bottom one is UITableViewCellAccessoryNone:

if(someCondition)
{
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{            
    cell.accessoryType = UITableViewCellAccessoryNone;
    // this didn't work
    // cell.layoutMargins = UIEdgeInsetsMake(0.0, 0, 0.0, 10.0);
}

What I'm trying to do is to move the two labels of the bottom cell to the left , so the right edge of both cells become aligned. I tried to do this by adding a layoutMargins to the bottom cell but it didn't work. Any idea how to do this?

Yar
  • 7,020
  • 11
  • 49
  • 69

1 Answers1

2

Set the bottom cell's accessoryView to an empty view with the needed width.

if(someCondition)
{
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.accessoryView = nil;
}
else
{            
    cell.accessoryType = UITableViewCellAccessoryNone;
    // Adjust the width value as needed
    cell.accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 5)];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks, this is exactly what I was looking for. Btw, what's the use of `cell.accessoryView = nil;`? – Yar Feb 09 '17 at 05:37
  • 1
    Cells get reused. You must always set each property for each condition. – rmaddy Feb 09 '17 at 05:42