开发者社区> 问答> 正文

collectionView修改标题的UILabel

每次用户点击collection view中的cell:
`- (void)collectionView:(UICollectionView )collectionView didSelectItemAtIndexPath:(NSIndexPath )indexPath
`

需要修改一个标题中的label:

UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header" forIndexPath:indexPath];

    UILabel *headerTitle=(UILabel *)[headerView viewWithTag:1];

    headerTitle.text=@"test";

每次tag都设置正确,但是内容并没改变,谢谢

展开
收起
爵霸 2016-03-17 11:15:20 1819 0
1 条回答
写回答
取消 提交回答
  • UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header" forIndexPath:indexPath];
     if(!headerView)
     {
     headerView = [[UICollectionReusableView alloc] initwith.....];
     }
     UILabel *headerTitle=(UILabel *)[headerView viewWithTag:1];
    headerTitle.text=@"test";

    另外你的view的tag设置成根据indexPath 来确定.

    2019-07-17 19:04:54
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载