【发布时间】:2015-01-02 11:29:30
【问题描述】:
如何做到这一点,以便当我在 XCode 中按下一个按钮时,其余按钮(包括按下的那个按钮)会被禁用?当然,我仍然希望该功能由按下的按钮执行。我只是不希望用户能够多次按下任何按钮,也不希望他们在已经按下第一个按钮后能够按下另一个按钮。在这种情况下,以下是我的两个按钮的 IBActions:
@IBAction func addVote1(sender: AnyObject) {
var query = PFQuery(className: "VoteCount")
query.getObjectInBackgroundWithId("BiEM17uUYT") {
(voteCount1: PFObject!, error: NSError!) ->Void in
if error != nil {
NSLog("%@", error)
} else {
voteCount1.incrementKey("votes")
voteCount1.saveInBackgroundWithTarget(nil, selector: nil)
}
let votes = voteCount1["votes"] as Int
let votes2 = voteCount1["votes2"] as Int
self.pollResults1.text = "\(votes) votes \(votes2) votes"
}
}
@IBAction func addVote2(sender: AnyObject) {
var query = PFQuery(className: "VoteCount")
query.getObjectInBackgroundWithId("BiEM17uUYT") {
(voteCount1: PFObject!, error: NSError!) -> Void in
if error != nil {
NSLog("%@", error)
} else {
voteCount1.incrementKey("votes2")
voteCount1.saveInBackgroundWithTarget(nil, selector: nil)
}
let votes = voteCount1["votes"] as Int
let votes2 = voteCount1["votes2"] as Int
self.pollResults2.text = "\(votes) votes \(votes2) votes"
}
}
}
【问题讨论】: