Permalink
Browse files

headers are now all added at beginning

  • Loading branch information...
1 parent 7d5fafd commit 823b12c806809e73edf8341a79dc8605f27544e5 @kolinkrewinkel committed Jul 28, 2011
Showing with 14 additions and 13 deletions.
  1. +14 −13 KKGridView/KKGridView.mm
View
@@ -274,7 +274,7 @@ - (CGFloat)heightForSection:(NSUInteger)section
CGFloat numberOfRows = 0.f;
if (_sectionItemCount.size() > 0) {
- numberOfRows = ceilf(_sectionItemCount[section] / (CGFloat)_numberOfColumns);
+ numberOfRows = ceilf(_sectionItemCount[section] / [[NSNumber numberWithUnsignedInt:_numberOfColumns] floatValue]);
} else {
numberOfRows = ceilf([_dataSource gridView:self numberOfItemsInSection:section] / (CGFloat)_numberOfColumns);
}
@@ -344,7 +344,7 @@ - (void)reloadContentSize
NSUInteger oldColumns = _numberOfColumns;
_numberOfColumns = [[NSString stringWithFormat:@"%f", self.bounds.size.width / (_cellSize.width + _cellPadding.width)] integerValue];
-
+
if (oldColumns != _numberOfColumns) {
_markedForDisplay = YES;
}
@@ -409,13 +409,17 @@ - (KKGridViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier
- (void)setCellSize:(CGSize)cellSize
{
_cellSize = cellSize;
- [self reloadContentSize];
+ if (_cellPadding.width != 0.f && _cellPadding.height != 0.f) {
+ [self reloadData];
+ }
}
- (void)setCellPadding:(CGSize)cellPadding
{
_cellPadding = cellPadding;
- [self reloadContentSize];
+ if (_cellSize.width != 0.f && _cellSize.height != 0.f) {
+ [self reloadData];
+ }
}
- (void)setDataSource:(id<KKGridViewDataSource>)dataSource
@@ -425,8 +429,6 @@ - (void)setDataSource:(id<KKGridViewDataSource>)dataSource
_flags.dataSourceRespondsToHeightForFooterInSection = [_dataSource respondsToSelector:@selector(gridView:heightForFooterInSection:)];
_flags.dataSourceRespondsToNumberOfSections = [_dataSource respondsToSelector:@selector(numberOfSectionsInGridView:)];
_flags.dataSourceRespondsToViewForHeaderInSection = [_dataSource respondsToSelector:@selector(gridView:viewForHeaderInSection:)];
-
- [self reloadData];
}
- (void)setGridDelegate:(id<KKGridViewDelegate>)gridDelegate
@@ -444,12 +446,13 @@ - (void)reloadData
if (_flags.dataSourceRespondsToViewForHeaderInSection) {
+ if (_headerViews) {
+ [[_headerViews allValues] makeObjectsPerformSelector:@selector(removeFromSuperview)];
+ [_headerViews removeAllObjects];
+ }
+
for (NSUInteger section = 0; section < _numberOfSections; section++) {
- if (_headerViews) {
- [[_headerViews allValues] makeObjectsPerformSelector:@selector(removeFromSuperview)];
- [_headerViews removeAllObjects];
- }
- if (!_headerViews) {
+ if (!_headerViews) {
_headerViews = [[NSMutableDictionary alloc] init];
}
UIView *header = [_dataSource gridView:self viewForHeaderInSection:section];
@@ -458,9 +461,7 @@ - (void)reloadData
CGFloat headerHeight = _headerHeights[section];
header.frame = CGRectMake(0.f, [self sectionHeightsCombinedUpToSection:section], self.bounds.size.width, headerHeight);
- NSLog(@"%@", NSStringFromCGRect(header.frame));
[self addSubview:header];
- [self sendSubviewToBack:header];
}
}
}

0 comments on commit 823b12c

Please sign in to comment.