小编idl*_*and的帖子

UILabel长按识别

编辑:将正确的代码添加到下面的代码中。工作中。

我的游戏运行时有一个位于顶部的标签。我希望能够长按标签并调出主菜单。现在,当我长按时,应用程序崩溃并出现以下错误。

错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[blocks1.ViewController longTap:]:无法识别的选择器发送到实例 0x101800000”*** 首先抛出调用堆栈:

我所拥有的基础知识:

var gameTopTitle = UILabel()

//this is all after my gameTopTitle is added to the screen
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.longTap))
gameTopTitle.addGestureRecognizer(longGesture)
gameTopTitle.isUserInteractionEnabled = true
Run Code Online (Sandbox Code Playgroud)

和函数

    func longTap(sender : UIGestureRecognizer){
    print("Long tap")
    if sender.state == .ended {
        print("UIGestureRecognizerStateEnded")
        //Do Whatever You want on End of Gesture
    }
    else if sender.state == .began {
        print("UIGestureRecognizerStateBegan.")
        //Do Whatever You want on Began of Gesture
    }
}
Run Code Online (Sandbox Code Playgroud)

ios swift

5
推荐指数
1
解决办法
1866
查看次数

跟踪用户投票(每个主题一票,即Reddit)

我正在开发一个应用程序,允许用户影响玩家排名和现场板(趋势足球)的趋势.

在此输入图像描述

正如您所看到的,您可以投票或下注玩家(仅当您通过Firebase(Google帐户)登录并进行身份验证时).否则,如果您没有登录,则不会投票.目前工作正常.

我的问题是,让每个用户只能对玩家投票一次的最简单方法什么.目前的实施允许任何玩家无限制上下投票.我想这样,所以我可以赞成汤姆布拉迪,但不能再投票给他.从那时起,我只能将其更改为不投票(通过再次点击)或downvote.我看到firebase中有User UID,所以我可以在允许投票通过之前检查UserUID是否已经对firebase数据库中的特定玩家进行了投票,但是如果用户只想更改一下该怎么办呢?投票投票?

这是处理投票的代码 -

downvotePlayer(playerId) {

this.state.user ?
  this.database.child(playerId).transaction(function (player) {
    if (player) {
      player.votes--
    }
    return player;
  })
  :
  console.log("Must log in to vote")

}

upvotePlayer(playerId) {
this.state.user ?
  this.database.child(playerId).transaction(function (player) {
    if (player) {
      console.log(player)
      player.votes++
    }
    return player;
  })
  :
  console.log("Must be logged in to vote.")

}
Run Code Online (Sandbox Code Playgroud)

这是Firebase的布局:

在此输入图像描述

如果我遗漏了任何重要信息,请告诉我,我会把它放在一个要点上.提前致谢.


编辑:

初始DB ref是

    this.database = firebase.database().ref().child('players');
Run Code Online (Sandbox Code Playgroud)

在向玩家添加upvote时,我这样做:

    this.database.child(playerId).transaction(function (player) {

    if (player) {
      var ref = firebase.database().ref('players').child('voters');
      ref.child(uid).set(1);
    }
Run Code Online (Sandbox Code Playgroud)

除了它在firebase中一起创建一个新节点之外,它几乎正在做它需要做的事情.

在此输入图像描述

"选民"应该在其上方的独特球员内部.我的问题显而易见吗?我很感激帮助先生.

firebase reactjs firebase-realtime-database

5
推荐指数
1
解决办法
388
查看次数