2014-09-26 38 views
1

您好,我正在從事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

回答

0

試試這個,我認爲這是重複使用的細胞,例如每次重置電池更換吹製法

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