【发布时间】:2015-08-03 11:38:15
【问题描述】:
我对 iOS 开发和使用树屋构建自毁 iOS 应用程序非常陌生,我们使用 parse.com 作为后端。
我在应用程序中添加了一个搜索栏:-
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
//dismiss keyboard and reload table
[self.searchBar resignFirstResponder];
[self.tableView reloadData];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
//Enable the cancel button when the user touches the search field
self.searchBar.showsCancelButton = TRUE;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
//disable the cancel button when the user ends editing
self.searchBar.showsCancelButton = FALSE;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
//dismiss keyboard
[self.searchBar resignFirstResponder];
//reset the foundUser property
self.foundUser = nil;
//Strip the whitespace off the end of the search text
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 {
//error occurred with query
}
}];
}
}
当我们搜索用户时,我们必须完全正确地获取用户名,包括完全正确地获取大写/小写字母,然后按搜索来显示用户。
即使我们没有正确获取大写/小写字母,我也希望用户显示,因此请进行不区分大小写的搜索。此外,如果用户没有正确获取用户名,我们可以为用户提供接近该用户名的用户。
【问题讨论】:
-
查看此链接。 stackoverflow.com/questions/31339298/…。我希望这个链接有用。
-
有点。谢谢,但我不确定如何集成它以从 parse.com 获取用户
标签: ios objective-c parse-platform uisearchbar pfquery