我正在尝试使用与当前用户相关的“created by”对象填充tableview中的cell.textlable.text。我得到的是所有用户的课程。
这就是我所拥有的:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithClassName:@"Lessons"];
self = [super initWithCoder:aDecoder];
if (self) {
// The className to query on
self.parseClassName = @"Lessons";
// The key of the PFObject to display in the label of the default cell style
self.keyToDisplay = @"Player";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = NO;
// The number of objects to show per page
self.objectsPerPage = self.Lessons.count;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:@"Lessons"];
[query includeKey:@"Player"];
[query includeKey:@"name"];
[query includeKey:@"updatedAt"];
[query includeKey:@"createdBy"];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:@"createdAt"];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *cellIdentifier = @"Lessoncell";
PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier];
}
这里我需要将所有玩家与当前用户相关联,而不仅仅是每个用户创建的所有玩家。
PFObject *player = object[@"Player"];
NSLog(@"%@", player);
[player fetchIfNeededInBackgroundWithBlock:^(PFObject *player, NSError *error) {
cell.textLabel.text = player[@"name"];
NSDate *updated = [object updatedAt];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Lesson Taken: %@", [dateFormat stringFromDate:updated]];
}];
return cell;
}