Skip to content

Commit

Permalink
Merge pull request #254 from fduch2k/master
Browse files Browse the repository at this point in the history
Fix for incorrect loading layout from nib
  • Loading branch information
steipete committed Mar 6, 2013
2 parents 45c19b8 + 11ab111 commit 5ef5c76
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
21 changes: 2 additions & 19 deletions PSTCollectionView/PSTCollectionView.m
Expand Up @@ -116,7 +116,6 @@ @interface PSTCollectionView() <UIScrollViewDelegate> {
// (We need to keep the total class size equal to the UICollectionView variant)
@interface PSTCollectionViewExt : NSObject
@property (nonatomic, unsafe_unretained) id<PSTCollectionViewDelegate> collectionViewDelegate;
@property (nonatomic, strong) id nibObserverToken;
@property (nonatomic, strong) PSTCollectionViewLayout *nibLayout;
@property (nonatomic, strong) NSDictionary *nibCellsExternalObjects;
@property (nonatomic, strong) NSDictionary *supplementaryViewsExternalObjects;
Expand Down Expand Up @@ -176,11 +175,7 @@ - (id)initWithCoder:(NSCoder *)inCoder {

PSTCollectionViewCommonSetup(self);

// add observer for nib deserialization.
id nibObserverToken = [[NSNotificationCenter defaultCenter] addObserverForName:PSTCollectionViewLayoutAwokeFromNib object:nil queue:nil usingBlock:^(NSNotification *note) {
self.extVars.nibLayout = note.object;
}];
self.extVars.nibObserverToken = nibObserverToken;
self.extVars.nibLayout = [inCoder decodeObjectForKey:@"UICollectionLayout"];

NSDictionary *cellExternalObjects = [inCoder decodeObjectForKey:@"UICollectionViewCellPrototypeNibExternalObjects"];
NSDictionary *cellNibs = [inCoder decodeObjectForKey:@"UICollectionViewCellNibDict"];
Expand All @@ -206,13 +201,6 @@ - (id)initWithCoder:(NSCoder *)inCoder {
- (void)awakeFromNib {
[super awakeFromNib];

// check if NIB deserialization found a layout.
id nibObserverToken = self.extVars.nibObserverToken;
if (nibObserverToken) {
[[NSNotificationCenter defaultCenter] removeObserver:nibObserverToken];
self.extVars.nibObserverToken = nil;
}

PSTCollectionViewLayout *nibLayout = self.extVars.nibLayout;
if (nibLayout) {
self.collectionViewLayout = nibLayout;
Expand All @@ -224,11 +212,6 @@ - (NSString *)description {
return [NSString stringWithFormat:@"%@ collection view layout: %@", [super description], self.collectionViewLayout];
}

- (void)dealloc {
id nibObserverToken = self.extVars.nibObserverToken;
if (nibObserverToken) [[NSNotificationCenter defaultCenter] removeObserver:nibObserverToken];
}

///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - UIView

Expand Down Expand Up @@ -1284,7 +1267,7 @@ - (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout {

- (void)setDelegate:(id<PSTCollectionViewDelegate>)delegate {
self.extVars.collectionViewDelegate = delegate;

// Managing the Selected Cells
_collectionViewFlags.delegateShouldSelectItemAtIndexPath = [self.delegate respondsToSelector:@selector(collectionView:shouldSelectItemAtIndexPath:)];
_collectionViewFlags.delegateDidSelectItemAtIndexPath = [self.delegate respondsToSelector:@selector(collectionView:didSelectItemAtIndexPath:)];
Expand Down
3 changes: 0 additions & 3 deletions PSTCollectionView/PSTCollectionViewLayout.h
Expand Up @@ -50,9 +50,6 @@ typedef NS_ENUM(NSUInteger, PSTCollectionViewItemType) {
- (BOOL)isCell;
@end

// used internally for deserialization until I figure out the proper way.
extern NSString *const PSTCollectionViewLayoutAwokeFromNib;

@interface PSTCollectionViewLayout : NSObject <NSCoding>

// Methods in this class are meant to be overridden and will be called by its collection view to gather layout information.
Expand Down
5 changes: 0 additions & 5 deletions PSTCollectionView/PSTCollectionViewLayout.m
Expand Up @@ -212,10 +212,7 @@ @interface PSTCollectionViewLayout() {
@property (nonatomic,copy,readonly) NSDictionary *decorationViewExternalObjectsTables;
@end

NSString *const PSTCollectionViewLayoutAwokeFromNib = @"PSTCollectionViewLayoutAwokeFromNib";

@implementation PSTCollectionViewLayout

///////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - NSObject

Expand All @@ -228,8 +225,6 @@ - (id)init {
_finalAnimationLayoutAttributesDict = [NSMutableDictionary new];
_insertedSectionsSet = [NSMutableIndexSet new];
_deletedSectionsSet = [NSMutableIndexSet new];

[[NSNotificationCenter defaultCenter] postNotificationName:PSTCollectionViewLayoutAwokeFromNib object:self];
}
return self;
}
Expand Down

0 comments on commit 5ef5c76

Please sign in to comment.