ios - UICollectionView 仅防止第一个单元格重复使用单元格

标签 ios uitableview xamarin uicollectionview

将 UICollectionView 与自定义 UICollectionViewCell 结合使用,我试图仅向第一个单元格添加一些额外信息。为此,我重写了 GetCell 方法

public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)

这很好用,第一个单元格显示了额外的信息。问题是单元格在 CollectionView 中再次被重新使用,额外的信息再次显示在那里。

如何防止重复使用 Collection View 中的第一个单元格?

谢谢!

最佳答案

几个选项:

  • 覆盖 UICollectionViewCell 的 prepareToReuse 方法,并重新设置 你在那个方法中想要什么
  • 首先使用不同的 reuseIdentifiers 和其他细胞
  • 对第一个和其他使用不同的原型(prototype)/类 细胞

要使用不同的重用标识符: 如果您通过原型(prototype)在 Storyboard 中执行此操作,请为第一个单元格创建另一个原型(prototype)并在您的 UITableViewDatasource 中执行类似的操作

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"FirstTableCell" forIndexPath:indexPath];
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:@"UsualTableCell" forIndexPath:indexPath];
    }
    return cell;
}

关于ios - UICollectionView 仅防止第一个单元格重复使用单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27434454/

相关文章:

ios - iOS 中的 If-Modified-Since 请求

c++ - iOS 不合格 id 错误

iOS - 静态单元格未出现在 UITableViewController 的子类中

iOS 11 刷新控件 + 搜索栏 = 刷新时缺少微调器

android - 为什么我的 Xamarin Forms 应用程序位于 Android 4.4 - API 19 (Samsung Galaxy S3) 中的所有其他应用程序之上?

ios - 从视频中提取缩略图时出现黑色空白图像

iphone - 在 iOS 6 的 TableView 中对数组进行排序

ios - 使用 Parse.com 和 swift 在 tableView 中加载异步图像

c# - 使用 MonoDroid 接收短信

azure - 使用适用于 Xamarin Android 的 Azure 移动服务从 Google Api 获取用户信息