在底部的行上写着self.pollResults1.text =“(percent1)%((投票))(percent2)%((votes2))”我收到的错误是'[UILabel]'没有名为'text'的成员。可能是因为我已将两个名为self.pollResults1.text的值分配给具有变量pollResults1的同一IBOutletCollection?我的IBOutletCollection的那一行位于顶部。我的IBOutletCollection设置错了吗?
@IBOutlet var pollResults1: [UILabel]!
@IBAction func addVote1(sender: AnyObject) {
for button in self.buttons {
button.enabled = false
}
}
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
let percent1 = votes * 100 / (votes + votes2)
let percent2 = votes2 * 100 / (votes + votes2)
self.pollResults1.text = "\(percent1)% (\(votes)) \(percent2)% (\(votes2))"
}
@IBAction func addVote2(sender: AnyObject) {
for button in self.buttons {
button.enabled = false
}
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
let percent1 = votes * 100 / (votes + votes2)
let percent2 = votes2 * 100 / (votes + votes2)
self.pollResults1.text = "\(percent1)% (\(votes)) \(percent2)% (\(votes2))"
}
}
}
答案 0 :(得分:1)
self.pollResults1是UILabel
的数组,而不是UILabel
- 正如消息所示,它没有属性text
。
你想要的是什么 -
self.pollResults1[0].text = "\(percent1)% (\(votes)) \(percent2)% (\(votes2))"