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