这是我的手机数据
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];
这是我在单元格中显示数据
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;
}
加载50张图片后,应用程序收到内存警告。
答案 0 :(得分:0)
无需检查 cell1 是否为零。如果您注册 [PhotoCell类] ,那么它将永远不会 nil 。
我相信您收到了内存警告,因为您没有重复使用单元格。
下面:
cell1= [arrayForCell objectAtIndex:indexPath.row-1];
你想要达到什么目标?