Autolayout is ignored in custom TableViewCell

落爺英雄遲暮 提交于 2019-12-24 19:20:04

问题


I'm trying to constrain some objects in my tableview cell so that they will be formatted correctly and won't clip on different devices. But, whenever I add a constraint to an object in there, it throws the object off screen to the top left. In the screenshot I attached I showed it with the green bar on the left but the same is true when I do it to the other labels and text fields.

Any ideas as to what I'm doing wrong?

  • I have a near identical table view that gets its data from another source and have them constrained the same way, but that tableview cell is formatted correctly when I build it.

  • I am seeing things online about Tableview cell subclasses. Is there something else I am supposed to be implementing in order to get these to stay? I'm not sure why they are working on one of my tableviews but not the other.

  • I am having the same issue that is being seen here Autolayout is ignored in Custom UITableViewCell but her answer is confusing me and I can't figure out how to reproduce it

This is what it looks like when the app is built:


回答1:


Figured it out. For anyone else who may have this problem in the future. You need to click on the content view in the Storyboard and go to the indemnity inspector. Then from there make sure the Class is set to the default of UIView and not the custom class of the TableView Cell.



来源:https://stackoverflow.com/questions/46027017/autolayout-is-ignored-in-custom-tableviewcell

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