[iOS]經過xib定義Cell而後關聯UICollectionView

先新建一個View的xib,而後刪掉自動生成的View,拖進一個UICollectionCell,再新建一個對應的UIView繼承UICollectionCell類。spa

OK,接下來該連outlet的就連。blog

設置delegate和dataSource繼承

而後一般咱們都要這樣,it

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("PersonalizedSettingsMovieCell", forIndexPath: indexPath) as PersonalizedSettingsMovieCell
        
        return cell
    }

但僅僅是這樣是不行的,找不到 PersonalizedSettingsMovieCell 的 Identifier,因此咱們要io

1.在xib裏面設置Cell的Identifier。class

2.UICollectionCell要設置queue

collectionView.registerNib(UINib(nibName: "PersonalizedSettingsMovieCell", bundle: nil), forCellWithReuseIdentifier: "PersonalizedSettingsMovieCell")
相關文章
相關標籤/搜索