I'm a new swift developer and simply; I'm trying to update the third row of CollectionView cell based on the other two cells ( third row will have a label in which it have the result of substitution of first row label and second row label) but I didn't find a solution to handle such an idea.
This is a list of attributes to handle the two values
var total : Int = 0
var totalp : Int = 0
This is the cellForItem function
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
if(indexPath.row == 0 ){
getSumSales { (success) in
if success{
cell.price.text = String(self.total).convertedDigitsToLocale(Locale(identifier: "AR"))
} else{
//It is not updated and some error occurred. Do what you want.
}
}
} else if (indexPath.row == 1){
getSumPurchses { (success) in
if success{
cell.price.text = String(self.totalp).convertedDigitsToLocale(Locale(identifier: "AR"))
} else{
//It is not updated and some error occurred. Do what you want.
}
}
} else if (indexPath.row == 2){
print(indexPath.count)
cell.flag.isHidden = true
var diffr=self.getDiff()
if(diffr > 0){
cell.price.textColor=UIColor.green
} else {
diffr *= -1
cell.price.textColor=UIColor.red
}
print(String(diffr))
cell.price.text = String(diffr).convertedDigitsToLocale(Locale(identifier: "AR"))
}
cell.name.text=locationName[indexPath.row]
cell.layer.borderWidth = 3
cell.layer.borderColor = UIColor.clear.cgColor
cell.layer.cornerRadius = 20
return cell
}
And this is the git difference function
func getDiff()-> Int{
let diff = self.total-self.totalp
return diff
}