試試這個,我認爲這是重複使用的細胞,例如每次重置電池更換吹製法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
cell = (HomeCollectionView *) [collectionView_ dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor lightGrayColor];
cell.CellImageView.image = [UIImage imageNamed:@"Mahasivaratri-Lord-Shiva.jpg"];
cell.title.text= [NSString stringWithFormat:@"%d",indexPath.row];
cell.badge.tag = indexPath.row;
//add this 2 lines
cell.badge.text = @""; //reset the text
cell.badge.frame = CGRectMake(cell.bounds.size.width-25,5,25,25); //and also frame of badge
//
if (indexPath.row == 1)
{
NSLog(@"unreadMessages---- Menu --- %d and Indexpath-- %ld",UnreadMessages,(long)indexPath.row);
NSInteger width = [self autoBadgeSizeWithString:[NSString stringWithFormat:@"%d",UnreadMessages]];
cell.badge.frame = CGRectMake(cell.frame.size.width-35, -10,width, 25);
cell.badge.text = [NSString stringWithFormat:@"%d",UnreadMessages];
NSLog(@"cell frame --- %@",cell.badge);
}
else
{
//other code
}
return cell;
}
請出示我們用你的細胞製造方法和你的「徽章我mplementation「代碼;) – 2014-09-26 07:09:48
@Z上面的鏈接總共有code – 2014-09-26 07:12:39
爲什麼你刪除'[cell.badge removeFromSuperview];'? – 2014-09-26 07:13:33