先新建一個View的xib,然后刪掉自動生成的View,拖進一個UICollectionCell,再新建一個對應的UIView繼承UICollectionCell類。
OK,接下來該連outlet的就連。
設置delegate和dataSource
然后通常我們都要這樣,
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{ let cell = collectionView.dequeueReusableCellWithReuseIdentifier("PersonalizedSettingsMovieCell", forIndexPath: indexPath) as PersonalizedSettingsMovieCell return cell }
但僅僅是這樣是不行的,找不到 PersonalizedSettingsMovieCell 的 Identifier,所以我們要
1.在xib里面設置Cell的Identifier。
2.UICollectionCell要設置
collectionView.registerNib(UINib(nibName: "PersonalizedSettingsMovieCell", bundle: nil), forCellWithReuseIdentifier: "PersonalizedSettingsMovieCell")