I have created a custom UITableViewCell
using xib.
The custom cell is simple and consists of an UILabel
that is pinned to the 4 edges of the "Content View" of the UITableViewCell
.
I would like to instantiate this cell and add it as a subview of a UIStackView
. I use the following code to instantiate the cell
let nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
let cell = nib.instantiate(withOwner: nil, options: nil).first as! CustomTableViewCell
stackView.addArrangedSubview(cell)
When the app is run, I observe that the size of the cell is not as expected. The height is smaller than expected and the label does not appear.
Using the "Debug View Hierarchy" in Xcode, I observe that some constraints have been added to the content view of the cell which causes this issue.
The UIView-Encapsulated-Layout-*
constraints seem to cause the issue. Can anyone point out how to solve the issue?
Note- If the custom UITableViewCell
is used in a UITableView
, then it appears as expected. The issue is observed only when the UITableViewCell
is instantiated manually.