Indentation not working on Custom UITableViewCell

ε祈祈猫儿з 提交于 2019-12-03 00:34:22

Indentation isn't the same as adjusting the content view when entering edit mode.

You're right, this seems simple and usually works almost straight out of the box. Typically the only things you need to change are the autoresizing masks of the components you add to the cell. Content on the left should have a fixed left margin, content on the right should have a fixed right margin.

When the cell enters editing mode the content view's size is adjusted to allow room for the editing accessories. If your content has these resizing masks, it will move along with this. Your layoutSubviews method above is quite likely undoing all this by setting the content view back to full width because you are using indentation incorrectly - though I can't be sure of that from the information in the question.

UPDATE

This is a issue (bug?) with constraints in UITableViewCells. You can go back to autoresizing masks by selecting the "File" tab in the storyboard / interface builder screen (if you want to use constraints elsewhere, use a standalone nib for the cell) and unchecking "Use Autolayout":

This arranges your cell content properly.

You can try these functions and work around them:

- (void)willTransitionToState:(UITableViewCellStateMask)state {
 [super willTransitionToState:state];

 if ((state & UITableViewCellStateEditingMask) || (state & UITableViewCellStateShowingDeleteConfirmationMask)) {
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.3];
  label.alpha = 0.0;

// LayoutSubview code [UIView commitAnimations]; } }

- (void)didTransitionToState:(UITableViewCellStateMask)state {
 [super didTransitionToState:state];

 if (!(state & UITableViewCellStateEditingMask) && !(state & UITableViewCellStateShowingDeleteConfirmationMask)) {
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.5];
  label.alpha = 1.0;
// LayoutSubview code
  [UIView commitAnimations];
 }
}

Unchecking "Use Autolayouts" did the trick for me.

Set the tableView edge inset to zero

[self.tableView setSeparatorInset:UIEdgeInsetsZero];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!