Custom UITableViewCell content doesn't move when editing

限于喜欢 提交于 2021-01-28 08:41:44

问题


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

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