我试图在我的应用上实现投票功能。用户必须按下一个按钮才能投票。用户按下后,他们不应该再次按下它。每次他们通过PFRelation投票(或按下按钮)时,我为用户创建了一个属性。我还添加了一个禁用按钮方法,可以阻止用户这样做,除非我的应用程序每次崩溃。我认为这可能与我在Parse中构造列的方式有关,但我喜欢听其他解决方案来实现此目的。下面是我尝试的禁用方法。Swift 2.0:如何禁止当前用户再次按下按钮?
我已经创建了一个禁用功能:
func disableButton(button: UIButton){
button.enabled = false
button.userInteractionEnabled = false
button.alpha = 0.5
}
它得到的残疾人在这里我voteButton功能:
@IBAction func voteButton(sender: UIButton) {
disableButton(sender)
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
self.userVote?.addObject(object!)
polls.addObject(object!)
object!.incrementKey("voteUp")
object!.saveInBackground()
self.tableView.reloadData()
NSLog("Top Index Path \(hitIndex?.row)")
}
这里是我的应用程序保持崩溃:
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
let cell = tableView!.dequeueReusableCellWithIdentifier("PollCell", forIndexPath: indexPath!) as! PollsApp
if let userPolls : PFObject = self.polls.objectAtIndex(indexPath!.row) as! PFObject {
if let voteCount = object[("voteUp")] as? Int {
cell.votersCounts.text = "\(voteCount)"
}
if (PFUser.currentUser()?["votedPost"] as! [String]).contains(userPolls.objectId!){
cell.disableButton(cell. voteButton)
}
什么是崩溃消息? – alinoz
你在碰撞报告中看到了什么? – Peyman
致命错误:意外地发现零,而展开一个可选值 – Bachenenad