您必须覆盖layoutSubviews
并执行以下操作。并且不要忘记将缩进级别设置为大于0的东西:)对于自定义单元格,默认情况下不会应用缩进级别。
为了避免单次滑动删除手势的缩进,您必须做更多的工作。有一个状态反映了单元格的编辑状态。它不是公开的,但可以通过- (void)willTransitionToState:(UITableViewCellStateMask)aState
访问,因此将它存储在属性中可以为layoutViews工作。
苹果的文档willTransitionToState:
注意,当用户刷细胞 删除它,细胞转变为 由 UITableViewCellStateShowingDeleteConfirmationMask 常数确定的状态,但 UITableViewCellStateShowingEditControlMask 是没有设置。
头文件
int state;
...
@property (nonatomic) int state;
...
单元实现
@synthesize state;
...
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing
&& ((state & UITableViewCellStateShowingEditControlMask)
&& !(state & UITableViewCellStateShowingDeleteConfirmationMask)) ||
((state & UITableViewCellStateShowingEditControlMask)
&& (state & UITableViewCellStateShowingDeleteConfirmationMask)))
{
float indentPoints = self.indentationLevel * self.indentationWidth;
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width - indentPoints,
self.contentView.frame.size.height);
}
}
- (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
self.state = aState;
}
您是否找到任何解决方案?我患有同样的问题。谢谢。 – harshitgupta 2013-06-05 09:07:48