ios - 如何查询用户的帖子?

标签 ios parse-platform

我目前通过 parse.com 设置我的系统

我想做的是能够在 tableViewPFQuerTableViewController 中查询 PFObject 的帖子我的用户已发布。目前我在下面有这段代码,它只说“正在加载..”而不是显示他们的帖子。为什么不显示我用户的最新帖子?

这是我试图获取用户帖子的查询:

- (PFQuery *)queryForTable {

    PFQuery *postQuery = [PFQuery queryWithClassName:@"New"];
    [postQuery whereKey:@"author" equalTo:[PFUser currentUser]];

    // Run the query
    [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            //Save results and update the table
            postArray = objects;
            [self.tableView reloadData];
        }
    }];
}

这是它的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    // If you want a custom cell, create a new subclass of PFTableViewCell, set the cell identifier in IB, then change this string to match
    // You can access any IBOutlets declared in the .h file from here and set the values accordingly
    // "Cell" is the default cell identifier in a new Master-Detail Project
    static NSString *CellIdentifier = @"Cell";

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

    // Configure the cell
    //cell.textLabel.text = [object objectForKey:self.textKey];
    //cell.imageView.file = [object objectForKey:self.imageKey];
    PFObject *post = [postArray objectAtIndex:indexPath.row];
    [cell.textLabel setText:[post objectForKey:@"title"]];

    return cell;
}

这里还有我发布 PFObject 的代码:

-(IBAction)done:(id)sender {

    PFUser *user = [PFUser currentUser];

    PFObject *quoteNew = [PFObject objectWithClassName:@"New"];
    [quoteNew setObject:user forKey:@"user"];
    [quoteNew setObject:[[self quoteText] text] forKey:@"quoteText"];
    [quoteNew setObject:[[self attributionTitle] text] forKey:@"title"];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"Uploading";
    [hud show:YES];

    [quoteNew saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {
            //[self done:self];
            [hud hide:YES];

            [self dismissViewControllerAnimated:YES completion:nil];

        } else {

             [hud hide:YES];

        }

    }];

最佳答案

您正在尝试在 queryForTable 方法中运行查询。这不是它的目的。在 queryForTable 中,您应该使用所需的约束(例如您添加的作者内容)构建查询,然后返回查询。所以对于你的情况:

- (PFQuery *)queryForTable {

    PFQuery *postQuery = [PFQuery queryWithClassName:@"New"];
    [postQuery whereKey:@"author" equalTo:[PFUser currentUser]];

    // Don't run the query, return it so PFQueryTableViewcontroller can use it
    return postQuery;
}

如果您想以编程方式告诉您的 PFQueryTableViewController 加载新帖子,您可以运行 [self loadObjects]

注意:这仅适用于您继承 PFQueryTableViewController 的情况

我建议阅读文档,它很好地安排了所有内容 here .

关于ios - 如何查询用户的帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897523/

相关文章:

ios - SecItemAdd 在 iOS 10 模拟器的 Xcode 8 中总是返回错误 -34018

ios - 静默通知不会在 TestFlight 中发送

javascript - 解析保存方法给出 400 错误

javascript - NOSQL 数据库存储和组织图像的最佳位置是什么

iphone - 如何用替换的 UINavigationController 推送 UIViewController

ios - 表格单元格很大

ios - 在 Firebase 数据库 Swift 3 中访问嵌套子项

ios - 根据用户是否登录有条件地显示不同的 View Controller

swift - 在 Swift 中检索对象的解析数组

iphone - 如何将数组分配给结构成员数组?