gpt4 book ai didi

ios - 使用 Parse.com iOS 搜索用户名以获取用户

转载 作者:行者123 更新时间:2023-11-29 01:42:09 25 4
gpt4 key购买 nike

我在 iOS 中实现了一个搜索栏,我必须输入准确的用户名才能让用户返回。我怎样才能改变它,以便它返回类似于我搜索的用户。我使用 parse.com 作为后端。

    NSString *searchText = [self.searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


//Check to make sure the field isnt empty and Query parse for username in the text field
if (![searchText isEqualToString:@""]) {

PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:searchText];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {

//check to make sure the query actually found a user
if (objects.count > 0) {

//set your foundUser property to the user that was found by the query (we use last object since its an array)
self.foundUser = objects.lastObject;

//The query was succesful but returned no results. A user was not found, display error message
} else {

}

//reload the tableView after the user searches
[self.tableView reloadData];

} else {

}

}];

在单元格中:

PFUser *user = self.foundUser;
if (self.foundUser) {

//set the label as the foundUsers username
cell.textLabel.text = self.foundUser.username;

我怎样才能让它变得更好,以便它显示相似的用户或具有我输入的字母的用户?

最佳答案

您是否尝试过 Parse 的 PFQuery 文档?看起来 PFQuery 有一个 whereKey:ContainsString: 方法可以满足您的需要。

https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/whereKey:containsString :

关于ios - 使用 Parse.com iOS 搜索用户名以获取用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32271943/

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