gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:03:20 25 4
gpt4 key购买 nike

我想在解析数据库中搜索用户,但是当我在搜索栏中输入用户名时,没有任何内容被添加到可用中。如何在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)
}

最佳答案

试试这个:

let query = PFQuery(className: "_User")

或者

让查询 = PFUser.query()

看看这个问题

Parse.com querying User class (swift)

关于ios - 为什么搜索栏没有从解析中提取用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32723226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com