I made a UICollectionView in my app but I can't figure out how to display different data for each cell I'm stuck with the same image I set it to in storyboard
the searching I've done has not resulted in any tutorials but I know that I customize my data in the UICollectionViewCell custom class
class CollectionViewCell: UICollectionViewCell {
//drawing a blank here...
}
if you could help me out I just want to put a button, two images and a couple labels (2-3) for each cell (there will be about 12 cells and I need them to have different data for each because i am trying to make a character selection screen)
with my current setup
class CharacterViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var array = [UIImage(named: "ideal image"),UIImage(named: "ideal image"),UIImage(named: "ideal image")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return array.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FirstCollectionViewCell", for: indexPath) as! FirstCollectionViewCell
return cell
}
}
i am able to display three of the exact same image but i need the cells to have separate customizable data i know all about .xib files and cocoa touch classes i use em all the time
one site i saw suggested using .xib files for each cell which i dont mind setting up but i need to know how to register the .xib files to be displayed as a cell if you know how could you help me out?
here is my cell
you guys are a huge help i think i know how to do it
- make cells with custom .xib files
- register .xib cells to array
- load array of cells into collectionView
- enjoy custom collectionView