Slide 5
Slide 5 text
ैདྷͷॻ͖ํ
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch section {
case 0:
return users.count
case 1:
return hobbies.count
case 2:
return teams.count
default:
fatalError()
}
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) ->
UICollectionViewCell {
switch (indexPath.section, indexPath.item) {
case (0, _):
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell
cell.configure(with: users[indexPath.item])
...
return cell
case (1, _):
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell
cell.configure(with: hobbies[indexPath.item])
...
return cell
case (2, _):
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell
cell.configure(with: teams[indexPath.item])
...
return cell
default:
fatalError()
}
}