I am trying to create a custom cell for my collection view. I have a xib named AccountCell
:
In my view containing the collection view:
profileViewController = p;
collectionView.dataSource = profileViewController
collectionView.registerClass(SocialAccountCell.self, forCellWithReuseIdentifier: "accountCell")
and then in the data source:
func collectionView(_collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
println("getting cell")
let cell = _collectionView.dequeueReusableCellWithReuseIdentifier("accountCell", forIndexPath: indexPath) as! SocialAccountCell
cell.test()
return cell
}
func collectionView(_collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return user!.accounts.count
}
SocialAccountCell.swift
:
class SocialAccountCell: UICollectionViewCell
{
func test()
{
println("Hello From collection cell")
}
}
Both "getting cell"
and "Hello From collection cell"
are printed but no blue cell appears in the collection view.
I tried adding an image to the cell to check if it was just the blue not working. Still no indication of any cell appearing.
What steps am I missing here?
Since you're using xib
to define a cell, I think you'd use collectionView.registerNib(UINib(nibName: "someNib", bundle: nil), forCellWithReuseIdentifier: "accountCell")
, or else you'd setup UI elements in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With