uitableview中的FBProfilePictureView每次都会重新创建它

时间:2013-11-23 09:36:02

标签: ios objective-c uitableview facebook-ios-sdk

我有一个UITableView,其中包含FBProfilePictureViewUILable

我的问题是,当用户滚动图片重建其自身并且需要时间来显示它自己的图像时,我想知道如何创建FBProfilePictureView一次然后当用户滚动它赢得'再次建立自我。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Messages *msg = [messages objectAtIndex:indexPath.row];
    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
    NSData *encodedDataObject = [def objectForKey:@"myUser"];
    User *user = (User *)[NSKeyedUnarchiver unarchiveObjectWithData: encodedDataObject];

    if(![msg.wrote_id isEqualToString:user.fid])
    {
        NSString *idToImage = [self getOtherUserId];
        NSString *CellIdentifier = @"Cell";
        ChatWindowCell *cell = nil;
        cell = (ChatWindowCell *)[tableChat dequeueReusableCellWithIdentifier:CellIdentifier];

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ChatWindowCell" owner:nil options:nil];
        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[ChatWindowCell class]])
            {
                cell = (ChatWindowCell *) currentObject;
                cell.profile_image.profileID=nil;
                if(cell.profile_image.profileID.length>0)
                {

                    return cell;
                }
                break;
            }
        }
        cell.profile_image.profileID = idToImage;
        NSString *text = msg.msg;
        cell.lblMessage.text=text;
        return cell;
    }
    else
    {
        NSString *CellIdentifier = @"Cell";
        ChatCellMe *cell = nil;
        cell = (ChatCellMe *)[tableChat dequeueReusableCellWithIdentifier:CellIdentifier];
        //  if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ChatCellMe" owner:nil options:nil];
        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[ChatCellMe class]])
            {
                cell = (ChatCellMe *) currentObject;
                NSLog(cell.prof_img.profileID);
                cell.prof_img.profileID=nil;

                if(cell.prof_img.profileID.length>0)
                {
                    return cell;
                }
                break;
            }
        }

        cell.prof_img.profileID = user.fid;
        NSString *text = msg.msg;
        cell.lblText.text=text;
        isMessageFromMe=false;
        return cell;

    }



}

任何帮助都会很棒......

非常感谢。

1 个答案:

答案 0 :(得分:2)

我创建了一个替代视图来解决此问题,请参阅https://github.com/combinatorial/DBFBProfilePictureView