【问题标题】:Restructure code from PSTCollectionView to UICollectionView将代码从 PSTCollectionView 重构为 UICollectionView
【发布时间】:2015-10-06 13:14:44
【问题描述】:

我已经从我的项目中完全删除了PSTCollectionView,在某一时刻,我收到以下错误,PSTCollectionViewItemTypeCell 未找到。我知道,我需要用 UICollectionView 提供的东西替换它,但我自己没有找到它。

有没有人经历过这两种情况 (PSTCollectionView/UICollectionView) 那么请给我建议一个替代方案来实现代码的和平。

从 iOS 6.0 及更高版本开始,这是一个罕见的问题 - 人们可以升级到 UICollectionViewsmoothly。但是,我正在运行一个旧项目,需要针对 iOS 9.0 进行完全重组。

请帮忙。

这是有问题的代码:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attributes = (UICollectionViewLayoutAttributes *)[super layoutAttributesForItemAtIndexPath:indexPath];
    if ([attributes representedElementCategory] == PSTCollectionViewItemTypeCell) {
        //some good code.
    }
    return attributes;
}

【问题讨论】:

    标签: ios objective-c uicollectionview pstcollectionview


    【解决方案1】:

    您可以从PSTCollectionView 存储库中看到PSTCollectionViewItemTypeCellPSTCollectionViewItemType 枚举的成员:

    typedef NS_ENUM(NSUInteger, PSTCollectionViewItemType) {
        PSTCollectionViewItemTypeCell,
        PSTCollectionViewItemTypeSupplementaryView,
        PSTCollectionViewItemTypeDecorationView
    };
    

    这基本上相当于UICollectionElementCategory

    typedef enum {
       UICollectionElementCategoryCell,
       UICollectionElementCategorySupplementaryView,
       UICollectionElementCategoryDecorationView 
    } UICollectionElementCategory;
    

    这应该是一个简单的替换另一个的情况:

    - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewLayoutAttributes *attributes = (UICollectionViewLayoutAttributes *)[super layoutAttributesForItemAtIndexPath:indexPath];
        if ([attributes representedElementCategory] == UICollectionElementCategoryCell) {
            //some good code.
        }
        return attributes;
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 2019-01-10
      • 1970-01-01
      相关资源
      最近更新 更多