TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Sash Zats.
UICollectionView
with UIViewController
s instad of cells.
View controller containment complient!
To run the example project, clone the repo, and run pod install
from the Example directory first.
#import <Voltron/Voltron.h>
Use WMLCollectionView
instead of UICollectionView
and WMLCollectionViewCell
for cells, displaying view controllers.
Set the collectionView.containerViewController
to the view controller that is hosting children view controllers.
Implement a data source method:
- (UIViewController *)collectionView:(WMLCollectionView *)collectionView controllerForIdentifier:(NSString *)identifier {
if ([identifier isEqualToString:@"Login"]) {
return [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
} else if ([identifier isEqualToString:@"Profile"]) {
return [self.storyboard instantiateViewControllerWithIdentifier:@"UserProfileViewController"];
}
}
didEndDisplayingCell:
passing the cell to give to the collection view a clue that it can be recycled.- (void)collectionView:(WMLCollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView didEndDisplayingCell:cell];
}
WMLCollectionView
host the regular cells along with view controller-based cells?Yes.
collectionView:controllerForIdentifier:
being called?The data source method is called only when a new view controller being created, when possible, view controllers are being reused just like regular cells.
It's definitely not. Only one time initialisation, and that is better be done in viewDidLoad
of the loaded view controller.
To configure your view controller with data, use -[WMLCollectionViewCell contentViewController]
The lifecycle of the view controller is preserved. When the view controller is about to be displayed, viewWillAppear:
and viewDidAppear:
are triggered.
Once the view controller goes away from the screen, viewWillDisappear:
and viewDidDisappear:
are triggered.
You should keep in mind that in performance critical areas might suffer when you're trying to display too many cells simultaneously.
Be wise about the moment of filling the collection view with data. E.g. it's probably better to differ displaying 200 small cells while playing an opening transition.
For smooth scrolling try to differ the population of the controller with data.
In that sense, test project is intended just as a showcase of how to use the API, but it's obviously not a typical use case from performance point of view.
collectionView:didEndDisplayingCell:forItemAtIndexPath:
?This project is intended as App Store-complient, therefore I wanted to implement it using the public API only.
collectionView:willDisplayCell:forItemAtIndexPath:
then?Project is intended to be iOS 7 compatible. Sadly, delegate method above is iOS 8+. Also, that's why you have to use a custom WMLCollectionViewCell
. To notify collection view that it's about to be shown.
I really don't know, meanwhile, an unrelated picture.
Voltron is available under the MIT license. See the LICENSE file for more info.
Sash Zats, [email protected]
Moof!