我有一个名为Messages的Parse.com类,其中我有3列:
- fromUser - Pointer<_User>
- toUser - Pointer<_User>
在我的UITableView中,我检索Messages-class中的所有对象,其中toUser等于PFUser currentUser。当我尝试为fromUser分配标签时,我收到此错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "username" has no data. Call fetchIfNeeded before getting its value.
以下是我查询的方式:
- (void)retriveMessages {
PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
[query whereKey:@"toUser" equalTo:[PFUser currentUser]];
[query orderByDescending:@"createdAt"];
query.limit = 1000;
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, error.userInfo);
} else {
// Found messages!
self.messages = objects;
[self.tableView reloadData];
[_message fetchIfNeeded];
NSLog(@"Retrived %d messages", self.messages.count);
}
}];
}
这就是我尝试将标签分配给fromUser-row的方式,这是一个指向User类的指针:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageCell" forIndexPath:indexPath];
_message = [_messages objectAtIndex:indexPath.row];
[_message fetchIfNeeded];
PFUser *user = (PFUser*)[_message objectForKey:@"fromUser"];
NSString *nameString = [user username];
cell.nameLabel.text = nameString;
cell.feedDelegate = self;
return cell;
}
答案 0 :(得分:3)
为了访问指向@&#34; fromUser&#34;的属性,你必须在find中急切地获取它。将其添加到查询中:
[query includeKey:@"fromUser"];