UICollectionviewCell不在ios 7上更新

问题描述:

您好,我正在从事UICollectionViewCell,在我的collectionview中总共有9个单元格,我想在索引'1'的CollectioviewCell上添加徽章图标。每次使用buttion操作更新带有int值的徽章。 问题是我第一次通过UIButton的行动更新徽章VALU,第一次它的工作好,但我更新了徽章第二次显示了在8细胞,再次更新徽章显示了7细胞,在1号位再次更新显示, my Sample Code is hereUICollectionviewCell不在ios 7上更新

什么是错在我的代码,请帮助我.. 在此先感谢

+0

请出示我们用你的细胞制造方法和你的“徽章我mplementation“代码;) – 2014-09-26 07:09:48

+0

@Z上面的链接总共有code – 2014-09-26 07:12:39

+0

为什么你删除'[cell.badge removeFromSuperview];'? – 2014-09-26 07:13:33

试试这个,我认为这是重复使用的细胞,例如每次重置电池更换吹制法

- (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; 
} 
+0

Thanq,其工作 – 2014-09-26 08:33:57