Post marked as solved
Post marked as solved with 7 replies, 1,137 views
Looking for some advice. Developing a gym app where the user will enter reps and lbs lifted per set per exercise. The collection of SET (per exercise) is a collection view which scrolls left to right. Here is my problem – after 4 sets are added and you scroll left and right the indexPath seems to get corrupted such that set 4 might have the values from set 1. I think it has to do with reloading the visible values and reusable cells. After the 5th cell I get a crash because of a nil value in the indexPath. The data is dynamically entered by the user and can be accessed in the Constants.Other.setsFromCollectionView variable (until thst also get corrupted with te scrolling).
Really stumped on this one. Any help would be very much appreciated.
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
self.collectionView.isPrefetchingEnabled = false
print("Cell tag: ", cell.tag)
let i = indexPath.item / numberOfSets
let j = indexPath.item % numberOfSets
let item = j * 5+i
if Constants.view_specific_workout_from_homeScrren.posted_bool == true {
cell.repsText.text = "0"
cell.weightText.text = "0"
Constants.view_specific_workout_from_homeScrren.posted_bool = false
}
cell.initialize(withDelegate: self)
cell.layer.cornerRadius = 15.0
cell.layer.borderWidth = 0.0
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.layer.shadowRadius = 3.0
cell.layer.shadowOpacity = 0.8
cell.layer.masksToBounds = false //<-
cell.layer.borderColor = UIColor.systemBlue.cgColor
cell.setnumber.text = ("Set " + String(indexPath.row + 1))
return cell
}