我該如何製作,以便當我按下XCode中的一個按鈕時,剩下的按鈕(包括被按下的按鈕)變爲禁用狀態?當然,我仍然希望通過按下按鈕來執行該功能。我只是不希望用戶能夠多次按下任何按鈕,也不希望他們在按下第一個按鈕後再按下另一個按鈕。下面是我爲我的兩個按鈕IBActions在這種情況下:如何在XCode中按下某個按鈕時禁用所有按鈕?
@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"
}
}
}
我已經爲兩個按鈕設置了IBOutlet屬性。我是否需要將惰性var添加到現有的IBOutlet屬性中,還是需要完全創建新的IBOutlet屬性? – ansariha 2014-11-06 04:16:41
添加了一些示例代碼供參考 - 您需要將其調整爲適合您的課程。 – 2014-11-06 04:17:30