How to use UICollectionViewController in storyboar

2019-04-02 16:01发布

问题:

It is a best practice to detect if a certain feature's class exists and degrade user's features depending on availability. I created UICollectionView in storyboard and a standard tableview to support ios 5.1 users. I then simply check if the user has this feature and segue to the appropriate scene. However, when I now try to compile my code I get a "dyld: Symbol not found: _UICollectionElementKindSectionHeader" This seems very anti-pattern of apple to not allow ios6.0 features in storyboard with a ios 5.1 deployment target.

if ([UICollectionView class]) {
    [self performSegueWithIdentifier:@"UserShow" sender:self];
} else {
    [self performSegueWithIdentifier:@"UserShowTable" sender:self];
}

The above seems like a pretty reasonable approach to me...

回答1:

You can't. As soon as you drop the collections view controller to the storyboard, it will try to reference it automatically, what will result in the compilation error you've got.



回答2:

I know this is not proper to put only link answers but her it is not possible to include the whole files.

Please see this.

A controller is designed to provide the same functionality as UICollectionController of iOS 6 but still supports to iOS 4/5

What developer is telling

PSTCollectionView
Open Source, 100% API compatible replacement of UICollectionView for iOS4.3+

You want to use UICollectionView, but still need to support iOS4/5? Then you'll gonna love this project. I've originally written it for PSPDFKit, my iOS PDF framework that supports text selection and annotations, but this project seemed way to useful for others to to keep it for myself :) Plus, I would love the influx of new gridviews to stop. Better just write layout managers and build on a great codebase.

The goal is to use PSTCollectionView on iOS 4/5 as a fallback and switch to UICollectionView on iOS6. We even use certain runtime tricks to create UICollectionView at runtime for older versions of iOS. Ideally, you just link the files and everything works on older systems. Practically, it's not that easy, and especially when you're using subclasses of UICollectionView-classes, since they can't be replaced at runtime.



回答3:

There's no compatibility solution for pre-6.0 deployment via storyboards, but PSTCollectionView does support iOS 5.0+ and is actively maintained. It does work at runtime to use UICollectionView* on 6.0 and later, and should be storyboard compatible.