熱門發問Pandas groupby mean of only positive values
管理員 提問於 7 個月 前發佈

I have the following function hooked up to a button. It is supposed to allow the user to like or if he has already liked the post, dislike it. We then have to make multiple changes in the DB to keep the info on the post up to date.
The problem I am having: When a new user first likes the post it works fine, then when he presses again it works fine again, BUT then when he taps again (expecting to like it again) the unlike function gets called again. How can I fix this? I have tried multiple things and still cant seem to find the solution
Here is the method:

@objc func like(_ tap: UITapGestureRecognizer) {

    if mediaTheUserLikes.count == 0 || (mediaTheUserLikes.count > numberMedia && mediaTheUserLikes[numberMedia] != "media(numberMedia+1)") {

        DispatchQueue.main.async {
            self.likeCurrentMedia()// self.getYourLikesForThisPost() is called as a closure in one of the methods here 
        }
        likes.tintColor = .red
    } else {
        likes.tintColor = .blue
        //He has already liked this which means he wants to unlike
        unlike() {
            self.getMediaStats()
            print("getYourLikesForThisPost 44")
            self.getYourLikesForThisPost()//I append values to this when this is called: mediaTheUserLikes
        }
    }
}
  • Share: