【问题标题】:How can I prevent reordering of the last cell in a UICollectionView?如何防止重新排序 UICollectionView 中的最后一个单元格?
【发布时间】:2012-11-26 05:41:30
【问题描述】:

我试图阻止集合视图中的最后一个单元格被重新排序。本质上,我希望“添加项目”单元格始终是集合中的最后一个单元格。

有什么想法吗?

提前致谢。

编辑:我正在使用LXReorderableCollectionViewFlowLayout 使用长按手势重新排列我的单元格。

【问题讨论】:

    标签: ios uicollectionview


    【解决方案1】:

    你可以试试这个……这对我有帮助……

              - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
                 {
                  return [array count]+1;
                  }
    
    
    
              - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
                   {
                   if (indexPath.row == ([array count]+1)) {
                        UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
                        headerLabel.text = @"your text";
                        headerLabel.frame = CGRectMake(110.0, 11.0, 100.0, 20.0);
                        [cell addSubview:headerLabel];
                        }
                     else
                       {
                       }
                   }
    

    希望对你有帮助。

    编码愉快。

    【讨论】:

    • 感谢您的回复。在我看来,您正在将标签添加到最后一个单元格的底部。当您尝试重新组织您附加 headerLabel 的单元格时会发生什么?它不会与单元格一起重新排序吗?
    【解决方案2】:

    我找到了一种非常简单的方法。

    The details of how to do so are here.

    本教程展示了如何在 UICollectionView 中设置补充视图(页眉或页脚)。我刚刚将我的标签和按钮添加到我的自定义补充视图中,瞧!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多