ios - 使用双击的投票系统

标签 ios swift parse-platform

我正在尝试在用户双击图像时实现投票系统。当用户双击图像时,投票计数会加一并保存以供解析。在我的牢房里我有

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        //postsLabel.textAlignment = NSTextAlignment.Center
        bottomBlurView.backgroundColor = UIColor(red: 0, green: 0.698, blue: 0.792, alpha: 0.75)
        votesLabel!.textAlignment = NSTextAlignment.Right
        let gesture = UITapGestureRecognizer(target: self, action: Selector("onDoubleTap:"))
        gesture.numberOfTapsRequired = 2
        contentView.addGestureRecognizer(gesture)

        heartIcon?.hidden = true
        //profileImageView.layer.cornerRadius = profileImageView.frame.height / 2

    }


func onDoubleTap (sender: AnyObject) {
        if self.complition != nil
        {
            self.complition!()
        }
        heartIcon?.hidden = false
        heartIcon?.alpha = 1.0

        UIView.animateWithDuration(1.0, delay:1.0, options:nil, animations: {
            self.heartIcon?.alpha = 0
            }, completion: {
                (value:Bool) in
                self.heartIcon?.hidden = true
        })
    }

    }

在我的 Collection View Controller 中我有

func onDoubleTap (indexPath:NSIndexPath)
{
    let cell = self.collectionView.cellForItemAtIndexPath(indexPath) as! NewCollectionViewCell

    let object = self.votes[indexPath.row]

    if let likes = object["votes"] as? Int
    {
        object["votes"] = likes + 1
        object.saveInBackgroundWithBlock{ (success:Bool,error:NSError?) -> Void in
            println("Data saved")

        }
        cell.votesLabel?.text = "\(likes + 1)"
                }
    else
    {
        object["votes"] = 1
        object.saveInBackgroundWithBlock{ (success:Bool,error:NSError?) -> Void in
            println("Data saved")
        }
        cell.votesLabel?.text = "1"
    }

}

但是这不会添加一个并且不会保存以进行解析。任何帮助表示赞赏。谢谢

最佳答案

您应该将第一个 onDoubleTap 放置在 collectionView 的 cellForItemAtIndexPath 中并在那里进行配置。

关于ios - 使用双击的投票系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31837216/

相关文章:

ios - UITableView 未显示正确的行数

android - 这段使用 parse.com 数据库存储数据的 Android 代码有什么问题

iOS 回到模态和导航 uiviewcontroller 中的根 ViewController

c# - 如何将使用 GKAchievement 的简单方法从 Objective-C 转换为 C#?

ios - Swift 和 SwiftUI 从 TextField 字符串绑定(bind)到模型已发布的可选 Integer 属性

ios - SocketIOClient-Swift : Unable to authenticate socket server

ios - ld : framework not found Parse Xcode 7 beta

ios - Bolts Framework的使用方法[Facebook+Parse]

ios - SKAction 未删除 Sprite

iphone - self 执行选择器 :withObject: afterDelay: does not call method