0

My Question is very simple,

I'm Learning iOS development and I'm stuck with tableviewcontroller

I can add Values to tableview with array, but when I try to append value from Parse, it's not working.

Here is the code:

var names: [String] = ["Name_one", "Name_two"]
let query: PFQuery! = PFUser.query()

override func viewDidLoad() {
    super.viewDidLoad()

    query.whereKey("objectId", notEqualTo: PFUser.currentUser()!.objectId!)

    query.findObjectsInBackgroundWithBlock { objects, error in
        if (error == nil) {
            for user: PFUser in (objects as! [PFUser]) {


            self.names.append(user.username as! String)

            }
        } else {
            print("Error")
        }
    }

Screen Shot Attachment

2
  • Update your question with relevant error details, so that we can help with debugging Commented Dec 11, 2015 at 3:42
  • there is no error, it's just that the value doesn't get appended to the array Commented Dec 11, 2015 at 3:45

1 Answer 1

1

You must to reload your tableview after get data finished

Code:

query.findObjectsInBackgroundWithBlock { objects, error in
    if (error == nil) {
        for user: PFUser in (objects as! [PFUser]) {


        self.names.append(user.username as! String)

        }
        yourTableview.reloadData()
    } else {
        print("Error")
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

How can I know, what's the name of my TableView? sry I'm really stuck at basics
OOP@@ i don't know, this is your uitableview. if you use UItableviewController so it is self.tableview. If you add UITableview to UIViewController , it 's outlet of tableview in storyboard
so do I need to add self.tableview.reloadData() ??
:D i 'm not sure because i don't know what 's your uitableview, but try it
I think it's self.tableView.reloadData().
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.