Skip to content
Browse files

Uses UIScrollView delegate property now

  • Loading branch information...
1 parent c5b9266 commit d6a7df499052de4553ad887049c94371188c59b2 @camh committed Feb 24, 2010
Showing with 22 additions and 19 deletions.
  1. +4 −5 CHGridView.h
  2. +17 −14 CHGridView.m
  3. +1 −0 README.markdown
View
9 CHGridView.h
@@ -28,7 +28,7 @@
// delegate protocol
-@protocol CHGridViewDelegate <NSObject>
+@protocol CHGridViewDelegate <NSObject,UIScrollViewDelegate>
@optional
- (void)selectedTileAtIndexPath:(CHGridIndexPath)indexPath inGridView:(CHGridView *)gridView;
- (void)visibleTilesChangedTo:(int)tiles;
@@ -44,7 +44,6 @@
NSMutableArray *reusableTiles;
id<CHGridViewDataSource> dataSource;
- id<CHGridViewDelegate> gridDelegate;
int sections;
NSMutableArray *sectionCounts;
@@ -65,6 +64,9 @@
CGFloat shadowBlur;
}
+@property (nonatomic, assign) id<CHGridViewDataSource> dataSource;
+@property (nonatomic, assign) id<CHGridViewDelegate,UIScrollViewDelegate> delegate;
+
@property (nonatomic) BOOL dynamicallyResizeTilesToFillSpace;
@property (nonatomic) BOOL allowsSelection;
@property (nonatomic) CGSize padding;
@@ -77,9 +79,6 @@
@property (nonatomic, retain) UIColor *shadowColor;
@property (nonatomic) CGFloat shadowBlur;
-- (void)setDataSource:(id<CHGridViewDataSource>)d;
-- (void)setGridDelegate:(id<CHGridViewDelegate>)d;
-
- (void)reloadData;
- (CHTileView *)dequeueReusableTileWithIdentifier:(NSString *)identifier;
View
31 CHGridView.m
@@ -25,7 +25,7 @@ - (void)calculateSectionTitleOffset;
@end
@implementation CHGridView
-@synthesize dynamicallyResizeTilesToFillSpace, allowsSelection, padding, preLoadMultiplier, rowHeight, perLine, sectionTitleHeight, shadowOffset, shadowColor, shadowBlur;
+@synthesize dataSource, dynamicallyResizeTilesToFillSpace, allowsSelection, padding, preLoadMultiplier, rowHeight, perLine, sectionTitleHeight, shadowOffset, shadowColor, shadowBlur;
- (id)init{
return [self initWithFrame:CGRectZero];
@@ -101,8 +101,8 @@ - (void)loadVisibleSectionTitlesForSectionRange:(CHSectionRange)range{
CHSectionTitleView *sectionTitle = nil;
- if([gridDelegate respondsToSelector:@selector(titleViewForHeaderOfSection:inGridView:)]){
- sectionTitle = [gridDelegate titleViewForHeaderOfSection:i inGridView:self];
+ if([[self delegate] respondsToSelector:@selector(titleViewForHeaderOfSection:inGridView:)]){
+ sectionTitle = [[self delegate] titleViewForHeaderOfSection:i inGridView:self];
[sectionTitle setFrame:CGRectMake(0, yCoordinate, b.size.width, sectionTitleHeight)];
}else{
sectionTitle = [[CHSectionTitleView alloc] initWithFrame:CGRectMake(0, yCoordinate, b.size.width, sectionTitleHeight)];
@@ -158,8 +158,8 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
CGRect rect = [layout tileFrameForIndexPath:indexPath];
- if([gridDelegate respondsToSelector:@selector(sizeForTileAtIndex:inGridView:)] && !dynamicallyResizeTilesToFillSpace){
- CGSize size = [gridDelegate sizeForTileAtIndex:indexPath inGridView:self];
+ if([[self delegate] respondsToSelector:@selector(sizeForTileAtIndex:inGridView:)] && !dynamicallyResizeTilesToFillSpace){
+ CGSize size = [[self delegate] sizeForTileAtIndex:indexPath inGridView:self];
CGRect centeredRect = [layout centerRect:CGRectMake(0, 0, size.width, size.height) inLargerRect:rect roundUp:NO];
centeredRect.origin.y += rect.origin.y;
centeredRect.origin.x += rect.origin.x;
@@ -230,7 +230,6 @@ - (void)reloadData{
sections = 1;
}
-
[sectionCounts removeAllObjects];
[layout setGridWidth:b.size.width];
@@ -275,7 +274,7 @@ - (void)layoutSubviews{
CHGridIndexRange tileRange = [layout rangeOfVisibleIndexesForContentOffset:contentOffsetY andHeight:b.size.height];
[self loadVisibleTilesForIndexPathRange:tileRange];
- if([gridDelegate respondsToSelector:@selector(visibleTilesChangedTo:)]) [gridDelegate visibleTilesChangedTo:visibleTiles.count];
+ if([[self delegate] respondsToSelector:@selector(visibleTilesChangedTo:)]) [[self delegate] visibleTilesChangedTo:visibleTiles.count];
if(sections > 1){
CHSectionRange sectionRange = [layout sectionRangeForContentOffset:contentOffsetY andHeight:b.size.height];
@@ -371,14 +370,18 @@ - (void)deselecSelectedTile{
}
}
-#pragma mark property setters
+#pragma mark property setters and getters
-- (void)setDataSource:(id<CHGridViewDataSource>)d{
- dataSource = d;
+- (id<CHGridViewDelegate>)delegate {
+ return (id<CHGridViewDelegate>)[super delegate];
}
-- (void)setGridDelegate:(id<CHGridViewDelegate>)d{
- gridDelegate = d;
+- (void)setDelegate:(id<UIScrollViewDelegate,CHGridViewDelegate>)d{
+ [super setDelegate:d];
+}
+
+- (void)setDataSource:(id<CHGridViewDataSource>)d{
+ dataSource = d;
}
- (void)setDynamicallyResizeTilesToFillSpace:(BOOL)dynamically{
@@ -427,8 +430,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UIView *view = [self hitTest:location withEvent:event];
if(selectedTile != nil && [selectedTile isEqual:view] && allowsSelection){
- if([gridDelegate respondsToSelector:@selector(selectedTileAtIndexPath:inGridView:)])
- [gridDelegate selectedTileAtIndexPath:[selectedTile indexPath] inGridView:self];
+ if([[self delegate] respondsToSelector:@selector(selectedTileAtIndexPath:inGridView:)])
+ [[self delegate] selectedTileAtIndexPath:[selectedTile indexPath] inGridView:self];
}
}
View
1 README.markdown
@@ -47,6 +47,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a
- Match or exceed speed and performance found in iPhone's Photos app grid view
- More UITableView cloning, like scrolling to a tile at a specific indexPath
+- Footer labels (with dynamic height) and footer views
- Tile labels
- Flexible per-line setting (maybe a range?)
- Horizontal scrolling and paging support

0 comments on commit d6a7df4

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