Search code examples
iosobjective-cuitableviewfacebook-ios-sdk

FBProfilePictureView in a uitableview recreates it self each time


I have a UITableView that holds an FBProfilePictureView and a UILable,

my problem is when a user scrolls the picture rebuilds its self and it takes time to show the image it self, i want to know how can i create the FBProfilePictureView once and then when the user scrolls it won't build it self again.

Here is my code:

- (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;

    }



}

any help would be great guys...

thanks a lot.


Solution

  • I created an alternate view to solve this problem, see https://github.com/combinatorial/DBFBProfilePictureView