我目前通过 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];
}
}];