Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Malthe Pedersen
Malthe Pedersen
2,338 Points

Won't update UILabel with data from Parse Database right away

Hello

Using the code below, the firstnameLabel (UILabel) will not update to the given data right away, i need to stop the app in xcode and run it again, to show the data in the UILabel. What can I do to update the UILabel right when the viewcontroller becomes visible? here is my code:

var currentUser = PFUser.currentUser()
        if currentUser != nil {


            var query = PFQuery(className:"_User")
            query.getObjectInBackgroundWithId(currentUser.objectId) {
                (bruger: PFObject!, error: NSError!) -> Void in
                if error == nil && bruger != nil {
                        var firstName: String = bruger["firstname"] as String
                        self.usernameLabel.text = firstName
                } else {
                    println("Error")
                }
            }


        } else {
            self.performSegueWithIdentifier("goto_login", sender: self)
        }