2017-10-11 70 views
0

我有一個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 
    } 
} 

enter image description here

我建立一個多的tableView: 的tableView - > tableViewCell - >的CollectionView - > CollectionViewCell - >標籤

+1

顯示一些代碼可能是? –

+0

你可以重新添加圖片嗎?並將您的代碼發佈到您的collectionViewCell中。 – Glenn

+0

您是否在任何地方註冊了collectionViewCell? – Hosny

回答

0

在uitableview單元格內爲uicollectionview設置數據源和委託。

override func awakeFromNib() { 
    //collection View Delegates 
    self.collectionView.delegate = self 
    self.collectionView.dataSource = self 
    super.awakeFromNib() 

    } 
+0

已經做到了,我說只有當我不添加約束時,標籤纔會顯示 –