Skip to content
Browse files

fixes crashes when using PSUI* classes, interoperability works now. I…

…mproves support for loading Nibs, but still not finished.
  • Loading branch information...
1 parent c5594ff commit a690c27cba044f0a98747375f302c6d654ca6c17 @steipete committed Sep 27, 2012
View
14 PSTCollectionView/PSTCollectionView.h
@@ -119,10 +119,10 @@ typedef NS_OPTIONS(NSUInteger, UICollectionViewScrollPosition) {
- (id)initWithFrame:(CGRect)frame collectionViewLayout:(PSTCollectionViewLayout *)layout; // the designated initializer
-@property (nonatomic, retain) PSTCollectionViewLayout *collectionViewLayout;
+@property (nonatomic, strong) PSTCollectionViewLayout *collectionViewLayout;
@property (nonatomic, assign) IBOutlet id <PSTCollectionViewDelegate> delegate;
@property (nonatomic, assign) IBOutlet id <PSTCollectionViewDataSource> dataSource;
-@property (nonatomic, retain) UIView *backgroundView; // will be automatically resized to track the size of the collection view and placed behind all cells and supplementary views.
+@property (nonatomic, strong) UIView *backgroundView; // will be automatically resized to track the size of the collection view and placed behind all cells and supplementary views.
// For each reuse identifier that the collection view will use, register either a class or a nib from which to instantiate a cell.
// If a nib is registered, it must contain exactly 1 top level object which is a PSTCollectionViewCell.
@@ -131,9 +131,8 @@ typedef NS_OPTIONS(NSUInteger, UICollectionViewScrollPosition) {
- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
-/*
+// TODO: implement!
- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;
- */
- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
- (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
@@ -187,6 +186,7 @@ typedef NS_OPTIONS(NSUInteger, UICollectionViewScrollPosition) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
#define PSUICollectionView PSUICollectionView_
#define PSUICollectionViewCell PSUICollectionViewCell_
+#define PSUICollectionReusableView PSUICollectionReusableView_
#define PSUICollectionViewDelegate PSTCollectionViewDelegate
#define PSUICollectionViewDataSource PSTCollectionViewDataSource
#define PSUICollectionViewLayout PSUICollectionViewLayout_
@@ -196,19 +196,21 @@ typedef NS_OPTIONS(NSUInteger, UICollectionViewScrollPosition) {
@interface PSUICollectionView_ : PSTCollectionView @end
@interface PSUICollectionViewCell_ : PSTCollectionViewCell @end
+@interface PSUICollectionReusableView_ : PSTCollectionReusableView @end
@interface PSUICollectionViewLayout_ : PSTCollectionViewLayout @end
@interface PSUICollectionViewFlowLayout_ : PSTCollectionViewFlowLayout @end
@interface PSUICollectionViewLayoutAttributes_ : PSTCollectionViewLayoutAttributes @end
@interface PSUICollectionViewController_ : PSTCollectionViewController <PSUICollectionViewDelegate, PSUICollectionViewDataSource> @end
#else
#define PSUICollectionView UICollectionView
-#define PSUICollectionViewCell UICollectionViewLayout
+#define PSUICollectionViewCell UICollectionViewCell
+#define PSUICollectionReusableView UICollectionReusableView
#define PSUICollectionViewDelegate UICollectionViewDelegate
#define PSUICollectionViewDataSource UICollectionViewDataSource
#define PSUICollectionViewLayout UICollectionViewLayout
#define PSUICollectionViewFlowLayout UICollectionViewCell
#define PSUICollectionViewLayoutAttributes UICollectionViewLayoutAttributes
#define PSUICollectionViewController UICollectionViewController
-#endif
+#endif
View
118 PSTCollectionView/PSTCollectionView.m
@@ -21,13 +21,16 @@ @interface PSTCollectionViewLayout (Internal)
CGFloat PSTSimulatorAnimationDragCoefficient(void);
@interface PSTCollectionView() {
+ id _nibObserverToken;
+ PSTCollectionViewLayout *_nibLayout;
+
BOOL _rotationActive;
NSMutableDictionary *_allVisibleViewsDict;
NSMutableDictionary *_cellReuseQueues;
NSMutableDictionary *_supplementaryViewReuseQueues;
NSMutableDictionary *_cellClassDict, *_cellNibDict;
- NSMutableDictionary *_supplementaryViewClassDict;
+ NSMutableDictionary *_supplementaryViewClassDict, *_supplementaryViewNibDict;
NSUInteger _reloadingSuspendedCount;
NSMutableSet *_indexPathsForSelectedItems;
@@ -53,7 +56,7 @@ @interface PSTCollectionView() {
} _collectionViewFlags;
}
@property (nonatomic, strong) PSTCollectionViewData *collectionViewData;
-@property (strong) NSString *collectionViewClassString;
+@property (nonatomic, strong) NSString *collectionViewClassString;
@end
@@ -62,52 +65,60 @@ @implementation PSTCollectionView
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - NSObject
+void PSTCollectionViewCommonSetup(PSTCollectionView *_self) {
+ _self.delaysContentTouches = NO;
+ _self->_indexPathsForSelectedItems = [NSMutableSet new];
+ _self->_indexPathsForHighlightedItems = [NSMutableSet new];
+ _self->_cellReuseQueues = [NSMutableDictionary new];
+ _self->_supplementaryViewReuseQueues = [NSMutableDictionary new];
+ _self->_allVisibleViewsDict = [NSMutableDictionary new];
+ _self->_cellClassDict = [NSMutableDictionary new];
+ _self->_cellNibDict = [NSMutableDictionary new];
+ _self->_supplementaryViewClassDict = [NSMutableDictionary new];
+}
+
- (id)initWithFrame:(CGRect)frame collectionViewLayout:(PSTCollectionViewLayout *)layout {
if ((self = [super initWithFrame:frame])) {
- // UICollectionViewCommonSetup
- self.delaysContentTouches = NO;
- layout.collectionView = self;
- _collectionViewLayout = layout;
- _indexPathsForSelectedItems = [NSMutableSet new];
- _indexPathsForHighlightedItems = [NSMutableSet new];
- _cellReuseQueues = [NSMutableDictionary new];
- _supplementaryViewReuseQueues = [NSMutableDictionary new];
- _allVisibleViewsDict = [NSMutableDictionary new];
- _cellClassDict = [NSMutableDictionary new];
- _cellNibDict = [NSMutableDictionary new];
- _supplementaryViewClassDict = [NSMutableDictionary new];
+ PSTCollectionViewCommonSetup(self);
+ self.collectionViewLayout = layout;
_collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
- _allowsSelection = YES;
}
return self;
}
- (id)initWithCoder:(NSCoder *)inCoder {
if ((self = [super initWithCoder:inCoder])) {
- self = [self initWithFrame:self.frame collectionViewLayout:nil];
+ PSTCollectionViewCommonSetup(self);
+ // add observer for nib deserialization.
+ _nibObserverToken = [[NSNotificationCenter defaultCenter] addObserverForName:PSTCollectionViewLayoutAwokeFromNib object:nil queue:nil usingBlock:^(NSNotification *note) { _nibLayout = note.object; }];
}
-
return self;
}
- (void)awakeFromNib {
+ [super awakeFromNib];
+
NSString *collectionViewClassString = [self valueForKeyPath:@"collectionViewClassString"];
-
- if (!collectionViewClassString) {
- NSLog(@"Please set the collection view class string in user defined runtime attributes");
- collectionViewClassString = NSStringFromClass([PSUICollectionViewFlowLayout class]);
+ if (collectionViewClassString) {
+ self.collectionViewLayout = [NSClassFromString(collectionViewClassString) new];
}
- PSTCollectionViewLayout *layout = [[NSClassFromString(collectionViewClassString) alloc] init];
- layout.collectionView = self;
- _collectionViewLayout = layout;
- _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
+ // check if NIB deserialization found a layout.
+ // TODO: is there no better way for this???
+ [[NSNotificationCenter defaultCenter] removeObserver:_nibObserverToken]; _nibObserverToken = nil;
+ if (_nibLayout) {
+ self.collectionViewLayout = _nibLayout; _nibLayout = nil;
+ }
}
- (NSString *)description {
return [NSString stringWithFormat:@"%@ collection view layout: %@", [super description], self.collectionViewLayout];
}
+- (void)dealloc {
+ if (_nibObserverToken) [[NSNotificationCenter defaultCenter] removeObserver:_nibObserverToken];
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - UIView
@@ -178,15 +189,19 @@ - (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)el
_supplementaryViewClassDict[identifier] = viewClass;
}
-
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier {
NSArray *topLevelObjects = [nib instantiateWithOwner:nil options:nil];
-
NSAssert(topLevelObjects.count == 1 && [topLevelObjects[0] isKindOfClass:PSTCollectionViewCell.class], @"must contain exactly 1 top level object which is a PSTCollectionViewCell");
_cellNibDict[identifier] = nib;
}
+- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier {
+ NSArray *topLevelObjects = [nib instantiateWithOwner:nil options:nil];
+ NSAssert(topLevelObjects.count == 1 && [topLevelObjects[0] isKindOfClass:PSTCollectionReusableView.class], @"must contain exactly 1 top level object which is a PSTCollectionReusableView");
+
+ _cellNibDict[identifier] = nib;
+}
- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
// dequeue cell (if available)
@@ -196,9 +211,8 @@ - (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath
[reusableCells removeObjectAtIndex:[reusableCells count]-1];
}else {
if (_cellNibDict[identifier]) {
- // Cell was registered via registerNib: forCellWithReuseIdentifier:
+ // Cell was registered via registerNib:forCellWithReuseIdentifier:
UINib *cellNib = _cellNibDict[identifier];
-
cell = [cellNib instantiateWithOwner:self options:0][0];
} else {
@@ -230,6 +244,11 @@ - (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseId
if (view) {
[reusableViews removeObjectAtIndex:reusableViews.count - 1];
} else {
+ if (_cellNibDict[identifier]) {
+ // supplementary view was registered via registerNib:forCellWithReuseIdentifier:
+ UINib *supplementaryViewNib = _supplementaryViewNibDict[identifier];
+ view = [supplementaryViewNib instantiateWithOwner:self options:0][0];
+ } else {
Class viewClass = _supplementaryViewClassDict[identifier];
Class reusableViewClass = NSClassFromString(@"UICollectionReusableView");
if (reusableViewClass && [viewClass isEqual:reusableViewClass]) {
@@ -245,6 +264,7 @@ - (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseId
} else {
view = [viewClass new];
}
+ }
view.collectionView = self;
view.reuseIdentifier = identifier;
}
@@ -318,7 +338,7 @@ - (NSIndexPath *)indexPathForCell:(PSTCollectionViewCell *)cell {
}
- (PSTCollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- //NSInteger index = [_collectionViewData globalIndexForItemAtIndexPath:indexPath];
+ // NSInteger index = [_collectionViewData globalIndexForItemAtIndexPath:indexPath];
// TODO Apple uses some kind of globalIndex for this.
__block PSTCollectionViewCell *cell = nil;
[_allVisibleViewsDict enumerateKeysAndObjectsWithOptions:0 usingBlock:^(id key, id obj, BOOL *stop) {
@@ -390,10 +410,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
}
-- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
-{
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
-
[self unhighlightAllItems];
}
@@ -447,8 +465,7 @@ - (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
}
}
-- (BOOL)highlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition notifyDelegate:(BOOL)notifyDelegate
-{
+- (BOOL)highlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition notifyDelegate:(BOOL)notifyDelegate {
BOOL shouldHighlight = YES;
if ([self.delegate respondsToSelector:@selector(collectionView:shouldHighlightItemAtIndexPath:)]) {
shouldHighlight = [self.delegate collectionView:self shouldHighlightItemAtIndexPath:indexPath];
@@ -466,8 +483,7 @@ - (BOOL)highlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animate
return shouldHighlight;
}
-- (void)unhighlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate
-{
+- (void)unhighlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate {
if ([_indexPathsForHighlightedItems containsObject:indexPath]) {
PSTCollectionViewCell *highlightedCell = [self cellForItemAtIndexPath:indexPath];
highlightedCell.highlighted = NO;
@@ -479,8 +495,7 @@ - (void)unhighlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)anima
}
}
-- (void)unhighlightAllItems
-{
+- (void)unhighlightAllItems {
for (NSIndexPath *indexPath in [_indexPathsForHighlightedItems copy]) {
[self unhighlightItemAtIndexPath:indexPath animated:NO notifyDelegate:YES];
}
@@ -489,13 +504,6 @@ - (void)unhighlightAllItems
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Update Grid
-- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout animated:(BOOL)animated {
- if (layout != _collectionViewLayout) {
- _collectionViewLayout = layout;
- [self reloadData];
- }
-}
-
- (void)insertSections:(NSIndexSet *)sections {
[self reloadData];
}
@@ -547,6 +555,20 @@ - (void)setBackgroundView:(UIView *)backgroundView {
}
}
+- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout animated:(BOOL)animated {
+ if (layout != _collectionViewLayout) {
+ _collectionViewLayout.collectionView = nil;
+ _collectionViewLayout = layout;
+ layout.collectionView = self;
+ _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
+ [self reloadData];
+ }
+}
+
+- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout {
+ [self setCollectionViewLayout:layout animated:NO];
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Private
@@ -731,6 +753,7 @@ - (NSInteger)item {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
@implementation PSUICollectionView_ @end
@implementation PSUICollectionViewCell_ @end
+@implementation PSUICollectionReusableView_ @end
@implementation PSUICollectionViewLayout_ @end
@implementation PSUICollectionViewFlowLayout_ @end
@implementation PSUICollectionViewLayoutAttributes_ @end
@@ -742,6 +765,7 @@ @implementation PSUICollectionViewController_ @end
// Dynamically change superclasses of the PSUICollectionView* clases to UICollectioView*. Crazy stuff.
if ([UICollectionView class]) class_setSuperclass([PSUICollectionView_ class], [UICollectionView class]);
if ([UICollectionViewCell class]) class_setSuperclass([PSUICollectionViewCell_ class], [UICollectionViewCell class]);
+ if ([UICollectionReusableView class]) class_setSuperclass([PSUICollectionReusableView_ class], [UICollectionReusableView class]);
if ([UICollectionViewLayout class]) class_setSuperclass([PSUICollectionViewLayout_ class], [UICollectionViewLayout class]);
if ([UICollectionViewFlowLayout class]) class_setSuperclass([PSUICollectionViewFlowLayout_ class], [UICollectionViewFlowLayout class]);
if ([UICollectionViewLayoutAttributes class]) class_setSuperclass([PSUICollectionViewLayoutAttributes_ class], [UICollectionViewLayoutAttributes class]);
@@ -750,6 +774,7 @@ @implementation PSUICollectionViewController_ @end
if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_6_0) {
objc_registerClassPair(objc_allocateClassPair([PSTCollectionView class], "UICollectionView", 0));
objc_registerClassPair(objc_allocateClassPair([PSTCollectionViewCell class], "UICollectionViewCell", 0));
+ objc_registerClassPair(objc_allocateClassPair([PSTCollectionReusableView class], "UICollectionReusableView", 0));
objc_registerClassPair(objc_allocateClassPair([PSTCollectionViewLayout class], "UICollectionViewLayout", 0));
objc_registerClassPair(objc_allocateClassPair([PSTCollectionViewFlowLayout class], "UICollectionViewFlowLayout", 0));
objc_registerClassPair(objc_allocateClassPair([PSTCollectionViewLayoutAttributes class], "UICollectionViewLayoutAttributes", 0));
@@ -759,6 +784,7 @@ @implementation PSUICollectionViewController_ @end
// add PSUI classes at rumtime to make Interface Builder sane.
objc_registerClassPair(objc_allocateClassPair([PSUICollectionView_ class], "PSUICollectionView", 0));
objc_registerClassPair(objc_allocateClassPair([PSUICollectionViewCell_ class], "PSUICollectionViewCell", 0));
+ objc_registerClassPair(objc_allocateClassPair([PSUICollectionReusableView_ class], "PSUICollectionReusableView", 0));
objc_registerClassPair(objc_allocateClassPair([PSUICollectionViewLayout_ class], "PSUICollectionViewLayout", 0));
objc_registerClassPair(objc_allocateClassPair([PSUICollectionViewFlowLayout_ class], "PSUICollectionViewFlowLayout", 0));
objc_registerClassPair(objc_allocateClassPair([PSUICollectionViewLayoutAttributes_ class], "PSUICollectionViewLayoutAttributes", 0));
View
33 PSTCollectionView/PSTCollectionViewCell.m
@@ -30,11 +30,10 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}
-- (void) awakeFromNib {
+- (void)awakeFromNib {
self.reuseIdentifier = [self valueForKeyPath:@"reuseIdentifier"];
}
-
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Public
@@ -98,40 +97,37 @@ - (id)initWithFrame:(CGRect)frame {
- (void)setSelected:(BOOL)selected {
if (_collectionCellFlags.selected != selected) {
_collectionCellFlags.selected = selected;
- [self _updateSelectionState];
+ [self updateSelectionState];
}
}
- (void)setHighlighted:(BOOL)highlighted {
if (_collectionCellFlags.highlighted != highlighted) {
_collectionCellFlags.highlighted = highlighted;
- [self _updateSelectionState];
+ [self updateSelectionState];
}
}
-- (void)_updateSelectionState
-{
+- (void)updateSelectionState {
BOOL shouldHighlight = (self.highlighted || self.selected);
_selectedBackgroundView.alpha = shouldHighlight ? 1.0f : 0.0f;
- [self _setHighlighted:shouldHighlight forViews:self.contentView.subviews];
+ [self setHighlighted:shouldHighlight forViews:self.contentView.subviews];
}
-- (void)_setHighlighted:(BOOL)highlighted forViews:(id)subviews
-{
+- (void)setHighlighted:(BOOL)highlighted forViews:(id)subviews {
for (id view in subviews) {
if ([view respondsToSelector:@selector(setHighlighted:)]) {
[view setHighlighted:highlighted];
}
- [self _setHighlighted:highlighted forViews:[view subviews]];
+ [self setHighlighted:highlighted forViews:[view subviews]];
}
}
- (void)menuGesture:(UILongPressGestureRecognizer *)recognizer {
NSLog(@"Not yet implemented: %@", NSStringFromSelector(_cmd));
}
-- (void)setBackgroundView:(UIView *)backgroundView
-{
+- (void)setBackgroundView:(UIView *)backgroundView {
if (_backgroundView != backgroundView) {
[_backgroundView removeFromSuperview];
_backgroundView = backgroundView;
@@ -140,8 +136,7 @@ - (void)setBackgroundView:(UIView *)backgroundView
}
}
-- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
-{
+- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView {
if (_selectedBackgroundView != selectedBackgroundView) {
[_selectedBackgroundView removeFromSuperview];
_selectedBackgroundView = selectedBackgroundView;
@@ -152,21 +147,18 @@ - (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
}
}
-- (BOOL)isSelected
-{
+- (BOOL)isSelected {
return _collectionCellFlags.selected;
}
-- (BOOL)isHighlighted
-{
+- (BOOL)isHighlighted {
return _collectionCellFlags.highlighted;
}
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - PSTCollection/UICollection interoperability
#import <objc/runtime.h>
-#import <objc/message.h>
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
NSMethodSignature *sig = [super methodSignatureForSelector:selector];
if(!sig) {
@@ -178,6 +170,7 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
}
return sig;
}
+
- (void)forwardInvocation:(NSInvocation *)inv {
NSString *selString = NSStringFromSelector([inv selector]);
if ([selString hasPrefix:@"_"]) {
@@ -191,4 +184,4 @@ - (void)forwardInvocation:(NSInvocation *)inv {
}
}
-@end
+@end
View
17 PSTCollectionView/PSTCollectionViewController.m
@@ -42,10 +42,19 @@ - (void)awakeFromNib {
- (void)loadView {
[super loadView];
- self.collectionView = [[PSTCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
- [self.view addSubview:self.collectionView];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
+
+ // if this is restored from IB, we don't have plain main view.
+ if ([self.view isKindOfClass:[PSTCollectionView class]]) {
+ _collectionView = (PSTCollectionView *)self.view;
+ }
+
+ // only create the collection view if it is not already created (by IB)
+ if (!_collectionView) {
+ self.collectionView = [[PSTCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
+ [self.view addSubview:self.collectionView];
+ self.collectionView.delegate = self;
+ self.collectionView.dataSource = self;
+ }
}
- (void)viewWillAppear:(BOOL)animated {
View
2 PSTCollectionView/PSTCollectionViewFlowLayout.m
@@ -287,4 +287,4 @@ - (void)updateItemsLayout {
_data.contentSize = contentSize;
}
-@end
+@end
View
3 PSTCollectionView/PSTCollectionViewLayout.h
@@ -73,7 +73,8 @@ typedef NS_ENUM(NSInteger, PSTCollectionUpdateAction) {
@end
*/
-
+// used internally for deserialization until I figure out the proper way.
+extern NSString *const PSTCollectionViewLayoutAwokeFromNib;
@interface PSTCollectionViewLayout : NSObject <NSCoding>
View
36 PSTCollectionView/PSTCollectionViewLayout.m
@@ -190,6 +190,8 @@ @interface PSTCollectionViewLayout() {
@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
@end
+NSString *const PSTCollectionViewLayoutAwokeFromNib = @"PSTCollectionViewLayoutAwokeFromNib";
+
@implementation PSTCollectionViewLayout
///////////////////////////////////////////////////////////////////////////////////////////
@@ -200,10 +202,21 @@ - (id)init {
_decorationViewClassDict = [NSMutableDictionary new];
_decorationViewNibDict = [NSMutableDictionary new];
_decorationViewExternalObjectsTables = [NSMutableDictionary new];
+ [[NSNotificationCenter defaultCenter] postNotificationName:PSTCollectionViewLayoutAwokeFromNib object:self];
}
return self;
}
+- (void)awakeFromNib {
+ [super awakeFromNib];
+}
+
+- (void)setCollectionView:(PSTCollectionView *)collectionView {
+ if (collectionView != _collectionView) {
+ _collectionView = collectionView;
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - Invalidating the Layout
@@ -289,6 +302,17 @@ - (void)setCollectionViewBoundsSize:(CGSize)size {
}
///////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - NSCoding
+
+- (id)initWithCoder:(NSCoder *)coder {
+ if((self = [self init])) {
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {}
+
+///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - PSTCollection/UICollection interoperability
#import <objc/runtime.h>
@@ -304,6 +328,7 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
}
return sig;
}
+
- (void)forwardInvocation:(NSInvocation *)inv {
NSString *selString = NSStringFromSelector([inv selector]);
if ([selString hasPrefix:@"_"]) {
@@ -324,15 +349,4 @@ - (void)forwardInvocation:(NSInvocation *)inv {
}
}
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSCoding
-
-- (id)initWithCoder:(NSCoder *)coder {
- self = [self init];
- return self;
-}
-
-- (void)encodeWithCoder:(NSCoder *)coder {
-}
-
@end

0 comments on commit a690c27

Please sign in to comment.
Something went wrong with that request. Please try again.