[英]Swift 3: UILabel not showing in custom UITableViewCell
I have a custom UITableViewCell
called CCLineupTableViewCell
that looks like this: 我有一个名为
CCLineupTableViewCell
的自定义UITableViewCell
,如下所示:
@IBOutlet weak var artistNameLabel: UILabel!
@IBOutlet weak var artistValuationLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
I access the cell in the cellForRowAt indexPath: IndexPath
method like so: 我在
cellForRowAt indexPath: IndexPath
方法中访问单元格, cellForRowAt indexPath: IndexPath
:
let cell = tableView.dequeueReusableCell(withIdentifier: "HomeCell", for: indexPath) as! CCLineupTableViewCell
My custom cell setup is like so: 我的自定义单元格设置如下:
As you can see it's setup right in the IB and in the code. 您可以在IB和代码中看到它的设置。 The weird thing is that the first label,
artistNameLabel
, is accessible through cellForRowAt indexPath: IndexPath
and works perfectly. 奇怪的是,第一个标签
artistNameLabel
可以通过cellForRowAt indexPath: IndexPath
并且工作正常。 The artistValuationLabel
, however, never even shows up despite having default text via the storyboard. 然而,尽管通过故事板具有默认文本,
artistValuationLabel
甚至从未出现过。
Edit: 编辑:
I've added a picture of the constraints from the nib. 我已经从笔尖添加了约束的图片。 It's anchored to the right side, top, and bottom of the cell (as well as the aspect ratio).
它固定在细胞的右侧,顶部和底部(以及纵横比)。
Your mistake is an error on the constraints you did set. 您的错误是您设置的约束错误。
Add a Width constraint to make sure that artistValuationLabel
will have space to appear. 添加宽度约束以确保
artistValuationLabel
将显示空格。
Due to improper width constraint this thing is happened. 由于宽度限制不当,这件事情发生了。 Either You need to add proportional width or you should run in that device for which you have designed.
您需要添加比例宽度,或者您应该在您设计的设备中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.