2015-08-24 54 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。并且您需要注册连接插座的笔尖 –