0

I want to search for users in the parse database, but when I type the username into the search bar nothing is being added to the uitable. How do I get the searched user on the uitableview? I tried printing the users into the console after searched but I'm not getting any names.

@IBOutlet weak var searchbar: UISearchBar!
var searchActive : Bool = false
var data:[PFObject]!
var filtered:[PFObject]!

override func viewDidLoad() {
searchbar.delegate = self
    search()
}

func search(searchText: String? = nil){
    let query = PFQuery(className: "User")
    if(searchText != nil){
        query.whereKey("username", containsString: searchText)
    }
    query.findObjectsInBackgroundWithBlock { (results, error) -> Void in
        self.data = results as? [PFObject]
        self.table3.reloadData()
    }

}
func tableView(tableView: UITableView, numberOfRowsInTableView: Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if(self.data != nil){
        println(self.data.count)
        return self.data.count
    }
    return 0
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell") as? UITableViewCell
    let obj = self.data[indexPath.row]
    cell!.textLabel!.text = obj["text"] as? String
    return cell!
}

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    searchActive = true;
}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
    searchActive = false;
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    searchActive = false;
}

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
    searchActive = false;
}

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
    search(searchText: searchText)
}
blee
  • 297
  • 4
  • 13

1 Answers1

0

Try this:

let query = PFQuery(className: "_User")

Or

let query = PFUser.query()

Check out this SO question

Parse.com querying User class (swift)

Community
  • 1
  • 1
JordanC
  • 1,303
  • 12
  • 28
  • Still not working, the search bar and the table are separate i can't embed it in a navigation controller since it's a xib file. – blee Sep 22 '15 at 17:52
  • What does that have to do with anything? Are you getting any data from Parse? Did you try printing the results of the query in the block of `findObjectsInBackgroundWithBlock`? – JordanC Sep 22 '15 at 17:59