我試圖在我的應用上實現投票功能。用戶必須按下一個按鈕才能投票。用戶按下後,他們不應該再次按下它。每次他們通過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