Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collectionview cell for xib not showing

Tags:

ios

swift

I am trying to create a custom cell for my collection view. I have a xib named AccountCell:

enter image description here

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?

like image 641
Deekor Avatar asked Jan 09 '23 08:01

Deekor


1 Answers

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.

like image 53
icodesign Avatar answered Jan 18 '23 08:01

icodesign