简体   繁体   中英

AutoLayout in nib file for UITableViewCell

I'm trying to re-create my UITableViewCell in a .xib so I can re-use it in multiple views. No matter what I do I can't seem to get AutoLayout to do its job when loading my .xib. I've tried setting translatesAutoresizingMaskIntoConstraints = false when I deque the cell. Any ideas as to what I could be doing wrong?

Thanks!

OK, I think I've finally got this figured out. It goes against other recommendations I've read online, but this is what I did. I basically had two problems:

1) My vertical constraints were not defined perfectly all the way down. In my case I had a vertical stack view, with other stack views embedded inside, but my main vertical stack view did not have a bottom constraint. Adding the bottom constraint fixed it.

2) Also: I've ran into problems with .xib (nibs) before where setting translatesAutoresizingMaskIntoConstraints = false makes it auto -layout properly. In my case it was calling this that was creating the problem. Removing this setting and making sure my constraints were defined all the way down seems to have worked.

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