2015-08-24 32 views
0

我使用xib(MyCustomCell.xib)創建了自定義UICollectionViewCell(我們稱之爲MyCustomCell),並且我想創建MyCustomCell的一個子類(我們稱之爲MyCustomCell2)。 MyCustomCell2(MyCustomCell)的父級有一個名爲titleLabel的IBOutlet。然而,對於titleLabel總是MyCustomCell2返回nil即使我做子類化從xib創建的自定義視圖

self.collectionView. 
      registerClass(MyCustomCell2.self, forCellWithReuseIdentifier: cellIdentifier); 

在viewDidLoad中

let cell = collectionView. 
     dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyCustomCell2; 
中的cellForRowAtIndexPath

任何在這個問題上是什麼樣的想法?

回答

0

首先,當您使用registerClass您的插座沒有連接。您需要使用registerNib

其次,網點需要連接在您正在加載的xib中。如果你正在加載你的子類的xib,你需要連接它的插座。

+0

但MyCustomCell與MyCustomCell2有不同的cellIdentifier,所以不會registerClass:cellReuseIdentifier導致崩潰? – user3808735

+0

@ user3808735你需要使用registerNib。並且您需要註冊連接插座的筆尖 –