Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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