Closed SubZane closed 5 years ago
It only crashes for me if I don't use the correct reuse identifier in the example project (in cellForItemAt
function). Can you confirm you use the correct one in dequeReusableCell
?
I think I am, but here's my code just in case.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.bodyPartPicker {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "body", for: indexPath) as! PillCell
cell.label.text = bodyparts[indexPath.row].bodypart
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "type", for: indexPath) as! PillCell
cell.label.text = titles[indexPath.row]
return cell
}
}
The code crashes on this row:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "type", for: indexPath) as! PillCell
Ah I see. The problem quite likely is on this line:
if collectionView == self.bodyPartPicker {
The bodyPartPicker
is CollectionPickerView
so this check will always fail. Try to change it to if collectionView == bodyPartPicker.collectionView
I think I found the error that made it crash
I need to reference the picker as well as the collectionView in my code, not necessary when using standard uicollectionviews
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.bodyPartPicker {
let bodycell = bodyPartPicker.collectionView.dequeueReusableCell(withReuseIdentifier: "body", for: indexPath) as! PillCell
bodycell.label.text = bodyparts[indexPath.row].bodypart
return bodycell
} else {
let typecell = typePicker.collectionView.dequeueReusableCell(withReuseIdentifier: "type", for: indexPath) as! PillCell
typecell.label.text = exerciseTypes[indexPath.row].type
return typecell
}
}
However. I still get the same values on the cells for both pickers. As if the cell I use is the same cell, for both pickers instead two separate instances of the cell..
I updated the file in your example by adding one more picker. Doesn't really work... I might be missing something but replacing it with a default uicollectionview will make it work.
Can you see if you can spot what's wrong? https://gist.github.com/SubZane/9421dcf48bcf607930df4b670b9bb7c5
Yes, as I said in my previous comment the picker is not UICollectionView
so you can't compare those two directly. The code will always go the else
branch trying to deque the "type" cell for both pickers - that's why it's crashing.
so, any suggestion on how to change my IF/ELSE statement? :)
Try if collectionView == self.bodyPartPicker.collectionView {
awesome! thanks :)
Cool, I'll close it then :).
I have a custom cell called PillCell. When trying to have two CollectionPickerViews at the same time I get an SIGABRT Error.
however, using a standard collectionview works perfectly
So my guess is there's a bug here somewhere