2015-01-11 40 views
3

我對於目標c是新手,並且我正在使用parse.com作爲社交媒體應用的數據庫。我想要做的是從我的POST表中抓取用戶的帖子。我使用指針從我的USER表中獲取用戶名,這很好,因爲您將在我的代碼中看到下面的內容,但是當我在將UILabel分配給用戶的帖子之前使用fetchifneeded時,我仍然收到此錯誤「關鍵「故事」沒有數據。在獲取其值之前調用fetchIfNeeded。「我感謝任何幫助,並感謝你的進步,如果我沒有讓我自己清楚,無論如何生病會更樂意擴大任何事情。在獲取其值之前需要解析調用獲取

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 
    if (indexPath.section == self.objects.count) { 
     UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath]; 
     return cell; 
    } 

    static NSString *CellIdentifier = @"StoryCell"; 

    NinetiesCell *cell = (NinetiesCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    //for the post of the user 
    PFObject *user = object[@"User"]; 
    [user fetchIfNeeded]; 
    //get username from pointer 
    cell.userName.text = user[@"username"]; 

    PFObject *story = [object objectForKey:@"Story"]; 
    [story fetchIfNeeded]; 
    cell.story.text = [object objectForKey:@"Story"]; 

    // Configure the cell 

    NSDate *updated = [object createdAt]; 

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 

    [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"]; 

    cell.dateLabel.text = [NSString stringWithFormat:@"%@", [dateFormat stringFromDate:updated]]; 

    return cell; 
} 
+0

你確定有關鍵'Story'的任何數據嗎? – Emil

+0

是的,我有它的工作之前,我調整它有一個像按鈕。 – rjsantiago77

+0

不應該是故事對象的'cell.story.text = story [@「text」]或其他值嗎?將PFObjext放入文本字​​段是沒有意義的 – Paulw11

回答

5

在你的情況下,一個更好的選擇是修改你的原始查詢以包括「用戶」和「故事」列,例如,

[query includeKey:@"User"]; 
[query includeKey:@"Story"]; 

然後,當你在tableView:cellForRowAtIndexPath:,他們將已經填充引用這些列,不需要調用fetchIfNeeded

+0

你幫助我大大地解決了我的問題,如果你想跳過我的問題並提供這個答案,我想給你信用。 http://codereview.stackexchange.com/questions/117331/amandas-relationship-tips-app-with-scroll-performance-issues?noredirect=1#comment218249_117331 –