简体   繁体   中英

UITableViewCell and setting subview frames in layoutSubviews doesn't work first time

I have a prototype UITableViewCell subclass in a storyboard that uses auto layout (but the cell itself doesn't have any elements using auto layout). I'm trying to set the frame of a subview manually in it's layoutSubviews method but this only works when the cell is reused, or is highlighted. The first time the cell is displayed, setting subview frames doesn't have an effect (but the method is called and setting background colours and stuff works fine). Is there something I'm missing?

EDIT: Ok I was wrong about the behaviour, it seems as though when reusing cells the subviews frames get reset again.

如果要强制单元格调用layoutSubviews,则可能需要在awakeFromNib中使用setNeedsLayout和layoutIfNeeded。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM