我目前通过 parse.com 设置我的系统
我想做的是能够在 tableView
或 PFQuerTableViewController
中查询 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/