UICollectionviewCell未在ios 7上更新
您好,我正在处理UICollectionviewCell未在ios 7上更新,ios,uicollectionview,uicollectionviewcell,Ios,Uicollectionview,Uicollectionviewcell,您好,我正在处理UICollectionViewCell,在我的collectionview中总共有9个单元格,我想在索引“1”处的CollectionViewCell上添加徽章图标。每次我都会使用buttion动作用int值更新徽章。 问题是我第一次通过UIbutton操作更新了badge valu,第一次运行良好,但第二次更新了第8单元的badge显示,第7单元的badge显示再次更新,第1位置的显示再次更新, 我的代码出了什么问题请帮助我。。 提前感谢尝试一下,我认为这是在重复使用电池,
UICollectionViewCell
,在我的collectionview中总共有9个单元格,我想在索引“1”处的CollectionViewCell上添加徽章图标。每次我都会使用buttion动作用int值更新徽章。
问题是我第一次通过UIbutton操作更新了badge valu,第一次运行良好,但第二次更新了第8单元的badge显示,第7单元的badge显示再次更新,第1位置的显示再次更新,
我的代码出了什么问题请帮助我。。
提前感谢尝试一下,我认为这是在重复使用电池,每次都重置电池,例如更换blow方法
- (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;
}
请在代码中向我们展示您的单元创建方法和“徽章实现”。)@Zil上面的链接有总代码为什么要删除
[cell.badge removeFromSuperview]代码>?Woops没有引起足够的注意。我现在正在看我只想在一个单元格上显示。在索引1处