我对iOS开发非常陌生,并且正在用treehouse构建一个自毁的iOS应用程序,我们使用parse.com作为后端。搜索栏无法响应iOS
我添加了一个搜索栏应用程序: -
- (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
}
}];
}
}
当我们搜索用户,我们必须得到用户名完全正确,包括越来越大/小写字母完全正确再按搜索用户显示。
我希望用户能够显示即使我们没有得到大写/小写字母,因此做一个不区分大小写的搜索。如果用户没有正确获取用户名,我们也可以为用户提供接近该用户名的用户名。
检查此链接。 http://stackoverflow.com/questions/31339298/how-to-search-array-of-dictionary-and-show-in-uitableview。我希望这个链接是有用的。 –
有点。谢谢,但我不知道如何将它集成到parse.com – smithyy