简体   繁体   English

搜索用户名以使用Parse.com iOS吸引用户

[英]Search usernames to get users with Parse.com iOS

i have implemented a search bar in iOS and i have to type in the exact username for a user to return. 我已经在iOS中实现了搜索栏,我必须输入确切的用户名才能返回用户。 How can i change that so it returns users similar to what i searched. 我该如何更改,以便它返回与我搜索的用户相似的用户。 I am using parse.com as a backend. 我正在使用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 {

            }

        }];

in cellforRow: 在cellforRow中:

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

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

how can i make it better so it shows similar users or users with the letters i type in? 我怎样才能使它更好,以便它显示相似的用户或带有我输入字母的用户?

Have you tried Parse's PFQuery documentation? 您是否尝试过Parse的PFQuery文档? Looks like PFQuery has a whereKey:ContainsString: method that might fulfill your need. 看起来PFQuery具有满足您需求的whereKey:ContainsString:方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM