I have a collectionViewCell
with a button I want to add a function to (like/unlike function) If user has liked the post the post tag should be set to 1,(color changed to blue) if user unlike the button tag it reset back to 0.(color changed to white) The problem I currently have is while scrolling random buttons within my collectionView button colors are being change, even when not selected.
class customCollectionViewCell: UICollectionViewCell {
@IBAction func followBtn(sender: UIButton) {
if (sender.tag == 0){
likePost{(msg)
in
if (msg == 0){
self.likeBtn.tintColor = UIColor.blueColor()
self.likeBtn.tag = 1
}
}
}
else{
//Unfollow function
self.likeBtn.tintColor = UIColor.whiteColor()
self.likeBtn.tag = 0
}
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("posterCell", forIndexPath: indexPath)
as! customCollectionViewCell
cell.likeBtn.tag = 0
if (cell.liketBtn.tag == 0){
cell.followArtistBtn.tintColor = UIColor.whiteColor()
}
if (cell.likeBtn.tag == 1){
cell.followArtistBtn.tintColor = UIColor.blueColor()
}
}