我有一个UITableView,其中包含一个FBProfilePictureView和一个UILable

我的问题是,当用户滚动图片时会重建其自身,并且花一些时间来显示其自身的图像,我想知道如何一次创建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;

    }



}

任何帮助都是很棒的人...

非常感谢。

最佳答案

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

关于ios - uitableview中的FBProfilePictureView每次都会自行重新创建,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20160758/

10-13 03:51