我有一個collectionViewCell,我向它添加了一個標籤,我將約束間隔設置爲最接近的鄰居((0,0,0,0)),所以必須將所有單元格調整並調整爲它的高度和寬度,但標籤根本沒有顯示。xcode:添加約束條件後不顯示標籤
我意識到,什麼都我把一個collectionCell,如果我添加到它的約束,它也無法顯示的,所以我最終刪除所有約束,並手動設置標籤的高度和寬度
CollectionViewCell:
import UIKit
class CollectionViewCell: UICollectionViewCell {
var text:String?
var delegate: TableViewCell?
@IBOutlet weak var label: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
loadFromNib() // load xib
let tap = UITapGestureRecognizer(target: self, action: #selector(tapFunc))
label.isUserInteractionEnabled = true
label.addGestureRecognizer(tap)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func tapFunc(_ sender: Any) {
// head will not be clickable cuz parent here gonna be nil
if let p = delegate {
if p.isUserInteractionEnabledWith(cell: self){
p.didTapeLabel(for: self, value: label.text!)
}
} else {
print("parent at collectionview cell is nil")
}
}
func fillOutData(_ text:String) {
label.text = text
}
}
我建立一個多的tableView: 的tableView - > tableViewCell - >的CollectionView - > CollectionViewCell - >標籤
顯示一些代碼可能是? –
你可以重新添加圖片嗎?並將您的代碼發佈到您的collectionViewCell中。 – Glenn
您是否在任何地方註冊了collectionViewCell? – Hosny