问题
I'm working on a Custom UITableViewCell with editing. When I enter editing mode, the label are not moved properly. This is the code in the .m file
- (id) init
{
self = [super init];
self.driverLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
self.lastMessageLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:self.driverLabel];
[self.contentView addSubview:self.lastMessageLabel];
return self;
}
The Custom cell is mapped on a cell in my StoryBoard. The labels are already placed on the right position.
What om I doing wrong here?
回答1:
You should use a fixed left margin because you want the left side of your label to stay a fixed distance from the left side of the content view, which gets shifted to the right when you enter editing mode.
You've used flexible left margin. So when the content view's width is reduced, and if the label no longer fits, the label's left margin will be reduced and it will not appear to shift to the right enough.
回答2:
I had the same problem.
My custom UITableViewCell would not slide to the right when the delete red circle control slid in from the left. It turned out to be because I had Layout set to Automatic in the Interfvace Builder Size Inspector.
I changed it to Translates Mask into Constraints and it works now.
来源:https://stackoverflow.com/questions/18616951/custom-uitableviewcell-content-doesnt-move-when-editing