1

ユーザーではなく PFObject を検索/クエリする方法を理解しようとしています。これは私がこれまでに行ったこととその発見ですが、表示されていません。この投稿を見つけてフォローしましたが、結果が表示されないため実行結果に至りませんでした。PFObject を表示する方法がわからないので、助けが必要です:)

-(void)filterResults:(NSString *)searchTerm {

    [self.searchResults removeAllObjects];

    PFQuery *query = [PFQuery queryWithClassName:@"New"];
    [query whereKeyExists:@"by"];  //this is based on whatever query you are trying to accomplish
    [query whereKeyExists:@"title"]; //this is based on whatever query you are trying to accomplish
    [query whereKey:@"title" containsString:searchTerm];

    NSArray *results  = [query findObjects];

    NSLog(@"%@", results);
   // NSLog(@"%u", results.count);

    [self.searchResults addObjectsFromArray:results];
}

次に、ここに表示しようとしています:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

       static NSString *CellIdentifier = @"Cell";
   PFTableViewCell *cell = (PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];   


    if (cell == nil) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


    cell.textLabel.text = [object objectForKey:self.textKey];



    if (tableView != self.searchDisplayController.searchResultsTableView) {

      /*  PFObject *title = [PFQuery queryWithClassName:@"title"];
        PFQuery *query = [PFQuery queryWithClassName:@"New"];
        PFObject *searchedUser = [query getObjectWithId:title.objectId]; NSString * usernameString = [searchedUser objectForKey:@"title"]; cell.textLabel.text = [NSString stringWithFormat:@"%@", usernameString];
       */
        PFQuery *query = [PFQuery queryWithClassName:@"New"];
        [query whereKey:@"title" equalTo:@"by"];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                // The find succeeded.
                NSLog(@"Successfully retrieved %d title", objects.count);
                // Do something with the found objects
                for (PFObject *object in objects) {
                    NSLog(@"%@", object.objectId);
                }
            } else {
                // Log details of the failure
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
        }];


    }
    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {

        PFQuery *query = [PFQuery queryWithClassName:@"New"];
        [query whereKey:@"title" equalTo:@"by"];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                // The find succeeded.
                NSLog(@"Successfully retrieved %d title", objects.count);
                // Do something with the found objects
                for (PFObject *object in objects) {
                    NSLog(@"%@", object.objectId);
                }
            } else {
                // Log details of the failure
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
        }];

       /* //PFObject *obj2 = [self.searchResults objectAtIndex:indexPath.row];
        PFQuery *query = [PFQuery queryWithClassName:@"New"];
        PFObject *searchedUser = [query getObjectWithId:obj2.objectId];
        NSString *first = [searchedUser objectForKey:@"title"];
        NSString *last = [searchedUser objectForKey:@"by"];
        cell.textLabel.text = [first substringToIndex:1];
        NSString *subscript = last;
       // cell.categoryName.text = [searchedUser objectForKey:@"category"];
        */
    }
    return cell;

}
4

1 に答える 1