UICollectionViewCell无法从Nib查找视图

时间:2016-12-21 13:08:46

标签: ios swift uicollectionview uicollectionviewcell

我有一个UICollectionView,我在其中使用自定义单元格。我正在viewDidLoad中注册单元格:

DisplayMetrics metrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(metrics);

并在cellForItemAt中设置它们:

self.collectionView.register(UINib(nibName: "IntroCell", bundle: nil), forCellWithReuseIdentifier: "IntroCell")

IntroCell看起来像这样:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell:IntroCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! IntroCell
    cell.refresh(cell: self.introScreens[indexPath.row])
    return cell
}

但每当我跑步时,我都会收到此错误:

class IntroCell : UICollectionViewCell{

    @IBOutlet weak var subtitle: UILabel!
    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var image: UIImageView!

    public func refresh(cell : IntroCellModel) {
        self.image.image = cell.image
        self.title.text = cell.title
        self.subtitle.text = cell.subtitle
    }

}

因为IntroCell中的视图是零。这是IB中设置的所有内容的屏幕截图。 enter image description here

0 个答案:

没有答案