Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在基于parseBased的iOS应用程序上搜索pfUsers?_Ios_Objective C_Parsing_Uitableview - Fatal编程技术网

如何在基于parseBased的iOS应用程序上搜索pfUsers?

如何在基于parseBased的iOS应用程序上搜索pfUsers?,ios,objective-c,parsing,uitableview,Ios,Objective C,Parsing,Uitableview,我目前正在制作一个应用程序,包括搜索和添加好友,但现在我被困在应用程序中搜索和列出用户的逻辑上 因此,基本上,如果搜索栏上键入的文本是“碧昂斯”,我希望匹配解析表中用户名列中的单词,如: 碧昂丝 碧昂斯卡特 碧昂斯克诺尔斯 (假设它们存在于应用程序中) 到目前为止,我已经在我的viewcontroller中创建了一个tableview: - (void) searchBarTextDidBeginEditing:(UISearchBar*)searchBar{ [searchBar se

我目前正在制作一个应用程序,包括搜索和添加好友,但现在我被困在应用程序中搜索和列出用户的逻辑上

因此,基本上,如果搜索栏上键入的文本是“碧昂斯”,我希望匹配解析表中用户名列中的单词,如:

碧昂丝 碧昂斯卡特 碧昂斯克诺尔斯 (假设它们存在于应用程序中)

到目前为止,我已经在我的viewcontroller中创建了一个tableview:

- (void) searchBarTextDidBeginEditing:(UISearchBar*)searchBar{
    [searchBar setShowsCancelButton:YES animated:YES];
    tableView=[[UITableView alloc]init];
    tableView.frame = CGRectMake(0,99,screenWidth,420);
    tableView.dataSource=self;
    tableView.delegate=self;
    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    [tableView reloadData];
    tableView.opaque = NO;
    tableView.backgroundView  = nil;
    [self.view addSubview:tableView];
}
这是我填充tableview的方式,但仅列出一个用户:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    [cell setExclusiveTouch:YES];
    cell.textLabel.text = [SearchList objectAtIndex:indexPath.row];

    return cell;
}
这是当用户单击搜索按钮时:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [searchBar resignFirstResponder];

    NSString *searchResult = [searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    PFQuery *query = [PFUser query];
    [query whereKey:@"username" matchesRegex:[NSString stringWithFormat:@"%@",searchResult]];
    [query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
        if (object) {
            PFUser *user = (PFUser *)object;
            NSLog(@"Username: %@", user.username);
            if (SearchList.count > 0) {
                [SearchList replaceObjectAtIndex:0 withObject:user.username];
            } else {
                [SearchList addObject:user.username];
            }
            [tableView reloadData];
        }
    }];

}

有人请指导我该做什么,因为我真的不能想清楚,谢谢

您不需要显示所有这些无关的UI代码。我将从你的问题字面上理解你的意图:

我想搜索用户名中包含“碧昂斯”的用户

你有没有试过看电影?这是一个非常用户友好、有用的资源,您应该能够比询问堆栈溢出问题更快地获取信息

为了您的利益,我将插入一段代码,帮助您实现以下目标:

您需要使用
PFQuery
对象,对其进行配置并异步运行(或与
findObjects
同步运行),如下所示:


我希望有帮助,下次使用文档

非常感谢!我也试过使用这些文档,但是弄糊涂了
PFQuery *query = [PFQuery queryWithClassName:@"Users"];
[query whereKey:@"username" containsString:@"Beyonce"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
  if (!error) {
    // No error; search succeeded.
    NSLog(@"%@", objects); // Your search results!
  } else {
    // Oh god. There was an error.
    NSLog(@"Error: %@ %@", error, [error userInfo]); // Log the error to debug.
  }
}];