0

This is my cell data

for (int s=0; s<[arrayForPhotosData1 count]; s++) {
    PhotoCell *cell=[[PhotoCell alloc] init];
    cell.imgPhoto.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    cell.imgPhoto.layer.shadowOffset = CGSizeMake(0, 2);
    cell.imgPhoto.layer.shadowOpacity = 1;
    cell.imgPhoto.layer.shadowRadius = 1.0;
    cell.imgPhoto.clipsToBounds = NO;
    if([[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"resolution_280_280"]!=NULL)
    {
        [cell.imgPhoto loadImage:[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"resolution_280_280"]];

    }
    [cell.ImgProfile loadImage:[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"profile_picture"]];
    [cell.lblUserName setText:[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"caption"]];
    [cell.lblForTime setText:[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"created_time"]];
    [cell.lblFullName setText:[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"Name" ]];
    [cell.btnForLike addTarget:self
                        action:@selector(addlikes:)
              forControlEvents:UIControlEventTouchUpInside];

    [cell.btnForLike  setImage:[UIImage imageNamed:@"like.png"] forState:UIControlStateNormal];
    [cell.btnForFavourite addTarget:self
                             action:@selector(addFavourite:)
                   forControlEvents:UIControlEventTouchUpInside];
    cell.btnForFavourite.tag=[[[arrayForPhotosData1  objectAtIndex:s]valueForKey:@"mediaid"] intValue];
    cell.btnForComment.tag=[[[arrayForPhotosData1  objectAtIndex:s]valueForKey:@"mediaid"] intValue];
    [cell.btnForComment addTarget:self action:@selector(addcomen:)forControlEvents:UIControlEventTouchUpInside];
    cell.imgPhoto.tag=[[[arrayForPhotosData1  objectAtIndex:s]valueForKey:@"mediaid"] intValue];
    [cell.imgPhoto addTarget:self action:@selector(addcoments:)forControlEvents:UIControlEventTouchUpInside];
    cell.btnForLike.tag=s;

    [cell.btnForLikeText setTitle:[NSString stringWithFormat:@"%@ Me gusta",[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"Totallikes"]] forState:UIControlStateNormal];

    [cell.btnForCommentText setTitle:[NSString stringWithFormat:@"%@ Commentarios",[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"TotalComment"]] forState:UIControlStateNormal];

    [cell.btnForLikeText addTarget:self
                            action:@selector(addlikes:)
                  forControlEvents:UIControlEventTouchUpInside];
    cell.btnForLikeText.tag=s;
    cell.btnForCommentText.tag=s;
    cell.btnForFavouritetext.tag=s;
    [cell.btnForFavouritetext addTarget:self
                                 action:@selector(addFavourite:)
                       forControlEvents:UIControlEventTouchUpInside];
    [cell.btnForCommentText addTarget:self action:@selector(addcomen:)forControlEvents:UIControlEventTouchUpInside];



    if([[[arrayForPhotosData1 objectAtIndex:s] valueForKey:@"FavoriteIsActive"] isEqualToString:@"true"])
    {

        [cell.btnForFavouritetext setTitle:[NSString stringWithFormat:@"%@ ",@"Favoritos"] forState:UIControlStateNormal];
    }
    [cell.btnForFavouritetext setTitle:[NSString stringWithFormat:@"%@ ",@"Favoritos"] forState:UIControlStateNormal];
    [arrayForCell addObject:cell];
}

[tableViewForPhotos reloadData];

and this is my displaying data in cell

static NSString *simpleTableIdentifier1 = @"TableItem1";

PhotoCell *cell1 = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier1];

if (cell1 == nil) {
    cell1 = [[PhotoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier1];
}

if ([arrayForCell count]>0) {
    cell1= [arrayForCell objectAtIndex:indexPath.row-1];

    cell1.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell1;
}

After loading 50 images, app is getting Received memory warning.

1 Answer 1

0

There's no need to check if cell1 is nil. If you registered [PhotoCell class], then it's never going to be nil.

I believe you're receiving a memory warning because you're not reusing cells.

Here:

cell1= [arrayForCell objectAtIndex:indexPath.row-1];

What are you trying to achieve?

6
  • Matteo Pacini In indexpath 0 I created another cell thats why I am Using [indexpath.row-1] Dec 29, 2013 at 6:14
  • Issue is: you're dequeuing a reusable cell (stored in cell1), and then you're discarding it when control reaches this line cell1= [arrayForCell objectAtIndex:indexPath.row-1] Dec 29, 2013 at 6:29
  • So what is the solution Dec 29, 2013 at 7:24
  • can u please tell me solution I am struggling 5 days Dec 29, 2013 at 7:24
  • The way you create cell is totally wrong. You should dequeue them inside cellForRowAtIndexPath. In MVC paradigm, you should use an array of models (e.g. data to populate your cells) instead of an array of cells. Dec 29, 2013 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.