Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ontroller

# By Nuno Sousa
# Via Norsez Orankijanan (2) and Nuno Sousa (1)
* 'master' of https://github.com/norsez/BDDynamicGridViewController:
  Remove default white background from cells
  Added ability to define number of views per cell
  • Loading branch information
norsez committed Dec 15, 2014
2 parents e97a8db + 6433895 commit 69821ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Classes/BDDynamicGridViewController.m
Expand Up @@ -170,14 +170,23 @@ - (void)reloadData
NSAssert(kMinViewsPerCell <= kMaxViewsPerCell, @"Minimum number of views per row cannot be greater than maximum number of views per row.");

while (accumNumOfViews < self.delegate.numberOfViews) {
NSUInteger numOfViews = (arc4random() % kMaxViewsPerCell) + kMinViewsPerCell;
if (numOfViews > kMaxViewsPerCell) {
numOfViews = kMaxViewsPerCell;
}
numOfViews = (accumNumOfViews+numOfViews <= self.delegate.numberOfViews)?numOfViews:(self.delegate.numberOfViews-accumNumOfViews);
NSUInteger numOfViews = 0;

ri = [BDRowInfo new];
ri.order = _rowInfos.count;
ri.accumulatedViews = accumNumOfViews;

if ([self.delegate respondsToSelector:@selector(numberOfViewsPerCell:)]) {
numOfViews = [self.delegate numberOfViewsPerCell:ri];
} else {
numOfViews = (arc4random() % kMaxViewsPerCell) + kMinViewsPerCell;

if (numOfViews > kMaxViewsPerCell) {
numOfViews = kMaxViewsPerCell;
}
numOfViews = (accumNumOfViews+numOfViews <= self.delegate.numberOfViews)?numOfViews:(self.delegate.numberOfViews-accumNumOfViews);
}

ri.viewsPerCell = numOfViews;
accumNumOfViews = accumNumOfViews + numOfViews;
_rowInfos = [_rowInfos arrayByAddingObject:ri];
Expand Down Expand Up @@ -304,6 +313,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
//clear for updated list of views
[cell setViews:nil];
cell.viewBorderWidth = self.borderWidth;
cell.backgroundColor = nil;

cell.rowInfo = ri;
NSArray * viewsForRow = [NSArray array];
Expand Down
5 changes: 5 additions & 0 deletions Classes/BDDynamicGridViewDelegate.h
Expand Up @@ -111,6 +111,11 @@
*/
- (void) gridViewDidEndScrolling;

/**
This method is called to determine the number of views in a cell.
@param rowInfo the row being calculated.
*/
- (NSUInteger)numberOfViewsPerCell:(BDRowInfo*)rowInfo;

/**
This method is called to determine the height of the specified row.
Expand Down

0 comments on commit 69821ed

Please sign in to comment.