为什么搜索栏没有从解析中提取用户?

时间:2015-09-22 17:30:38

标签: ios swift parse-platform

我想在解析数据库中搜索用户,但是当我在搜索栏中输入用户名时,没有任何内容被添加到uitable中。如何在uitableview上获取搜索到的用户?我在搜索后尝试将用户打印到控制台,但我没有得到任何名字。

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

1 个答案:

答案 0 :(得分:0)

试试这个:

让query = PFQuery(className:“_ User”)

或者

让query = PFUser.query()

查看此SO问题

Parse.com querying User class (swift)