ansariha
ansariha

Reputation: 61

UILabel does not have a label named 'text'

On the line at the bottom that says self.pollResults1.text = "(percent1)% ((votes)) (percent2)% ((votes2))" I'm getting an error that says '[UILabel]' does not have a member named 'text'. Could that be because I've assigned two values called self.pollResults1.text to the same IBOutletCollection with the variable pollResults1? That line with my IBOutletCollection is on the top. Did I set up my IBOutletCollection wrong?

@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))"
        }
    }
}

Upvotes: 0

Views: 925

Answers (1)

Paulw11
Paulw11

Reputation: 115041

self.pollResults1 is an array of UILabel, not a UILabel - so as the message says, it doesn't have a property text.

What you want is something like -

self.pollResults1[0].text = "\(percent1)% (\(votes))        \(percent2)% (\(votes2))"

Upvotes: 1

Related Questions