Skip to content
This repository has been archived by the owner on Feb 16, 2019. It is now read-only.

Commit

Permalink
Fixed reloading bug in collection view
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jun 13, 2011
1 parent 3ef3ac4 commit b2de4a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 4 additions & 0 deletions SSCatalog/Classes/SCCollectionViewDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ - (void)viewDidLoad {
self.title = [[self class] title];

self.collectionView.extremitiesStyle = SSCollectionViewExtremitiesStyleScrolling;

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Reload" style:UIBarButtonItemStyleBordered target:self.collectionView action:@selector(reloadData)];
self.navigationItem.rightBarButtonItem = button;
[button release];
}


Expand Down
36 changes: 20 additions & 16 deletions SSToolkit/SSCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ - (id)initWithFrame:(CGRect)frame {


- (void)setFrame:(CGRect)frame {
BOOL shouldReload = (CGSizeEqualToSize(frame.size, self.frame.size) == NO);
[super setFrame:frame];
[_tableView reloadData];

if (shouldReload) {
[self reloadData];
}
}


Expand Down Expand Up @@ -376,30 +380,30 @@ - (NSUInteger)_numberOfRowsInSection:(NSUInteger)section {
if (numberOfRows) {
return [numberOfRows unsignedIntegerValue];
}
NSUInteger totalItems = [self numberOfItemsInSection:section];
NSUInteger itemsPerRow = [self _numberOfItemsPerRowForSection:section];
if (itemsPerRow == 0) {
return 0;
}
NSUInteger rows = (NSUInteger)ceilf(totalItems / itemsPerRow);
// Check for headers and footers

NSUInteger totalItems = [self numberOfItemsInSection:section];
NSUInteger itemsPerRow = [self _numberOfItemsPerRowForSection:section];

if (itemsPerRow == 0) {
return 0;
}

NSUInteger rows = (NSUInteger)ceilf(totalItems / itemsPerRow);

// Check for headers and footers
if (_extremitiesStyle == SSCollectionViewExtremitiesStyleScrolling) {
if ([self _sectionInfoItemForKey:kSSCollectionViewSectionHeaderViewKey section:section]) {
rows++;
}

if ([self _sectionInfoItemForKey:kSSCollectionViewSectionFooterViewKey section:section]) {
rows++;
}
}

[self _setSectionInfoItem:[NSNumber numberWithUnsignedInteger:rows] forKey:kSSCollectionViewSectionNumberOfRowsKey section:section];
return [numberOfRows unsignedIntegerValue];

return rows;
}


Expand Down
6 changes: 0 additions & 6 deletions SSToolkit/SSCollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ - (void)loadView {
}


- (void)viewDidLoad {
[super viewDidLoad];
[_collectionView reloadData];
}


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_collectionView.scrollView flashScrollIndicators];
Expand Down

0 comments on commit b2de4a2

Please sign in to comment.