【发布时间】:2016-03-05 21:10:42
【问题描述】:
我正在尝试在我的应用上实现投票功能。用户必须按下按钮才能投票。用户按下后,不应再按下。每次用户通过 PFRelation 投票(或按下按钮)时,我都会为他们创建一个属性。我还添加了一个禁用按钮方法,该方法会阻止用户执行此操作,除非我的应用程序在每次执行此操作时都会崩溃。我认为这可能与我在 Parse 中构建列的方式有关,但我喜欢听听其他解决方案来做到这一点。我尝试的禁用方法如下。
我创建了一个禁用函数:
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)
}
【问题讨论】:
-
什么是崩溃信息?
-
您在崩溃报告中看到了什么?
-
致命错误:在展开可选值时意外发现 nil
-
我不是 100% 确定如果它是一个关系,你甚至需要这样做 - 我认为 Parse 不允许同一个用户两次填充一个关系......
-
你认为我应该为 saveInBackground() 调用更好的方法吗?
标签: ios swift parse-platform tableview