Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

KKGridViewDelegate inheritances from UIScrollViewDelegate #132

Merged
merged 1 commit into from

4 participants

@blommegard

This makes more sense and is "UITableView-style".

@kolinkrewinkel kolinkrewinkel merged commit 30c1408 into from
@jonsterling
Collaborator

@blommegard Thanks for this! After KKGridView was modified to no longer require being its own UIScrollViewDelegate, this is a welcome change.

@zadr

I agree, awesome change! :D

However, why access the delegate through a property now, instead of direct ivar access like elsewhere?

And, I think that it would make sense to keep the gridDelegate property around (where -setGridDelegate: does nothing but call -setDelegate: on self) and marked as deprecated (with __attribute__((deprecated))), instead of getting rid of it completely. This way, people who update KKGridView won't suddenly find their build broken.

Collaborator

I'm with @jonsterling on this one, it's still in an early development phrase.

The phase of development doesn't matter much, if people are using it in the wild.

Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
58 KKGridView/KKGridView.h
@@ -29,8 +29,33 @@ typedef enum {
KKGridViewAnimationNone
} KKGridViewAnimation;
-@protocol KKGridViewDataSource;
-@protocol KKGridViewDelegate;
+@class KKGridView;
+
+@protocol KKGridViewDataSource <NSObject>
+@required
+- (NSUInteger)gridView:(KKGridView *)gridView numberOfItemsInSection:(NSUInteger)section;
+- (KKGridViewCell *)gridView:(KKGridView *)gridView cellForItemAtIndexPath:(KKIndexPath *)indexPath;
+@optional
+- (NSUInteger)numberOfSectionsInGridView:(KKGridView *)gridView;
+- (NSString *)gridView:(KKGridView *)gridView titleForHeaderInSection:(NSUInteger)section;
+- (NSString *)gridView:(KKGridView *)gridView titleForFooterInSection:(NSUInteger)section;
+- (CGFloat)gridView:(KKGridView *)gridView heightForHeaderInSection:(NSUInteger)section;
+- (CGFloat)gridView:(KKGridView *)gridView heightForFooterInSection:(NSUInteger)section;
+- (UIView *)gridView:(KKGridView *)gridView viewForHeaderInSection:(NSUInteger)section;
+- (UIView *)gridView:(KKGridView *)gridView viewForFooterInSection:(NSUInteger)section;
+- (UIView *)gridView:(KKGridView *)gridView viewForRow:(NSUInteger)row inSection:(NSUInteger)section; // a row is compromised of however many cells fit in a column of a given section
+- (NSArray *)sectionIndexTitlesForGridView:(KKGridView *)gridView;
+- (NSInteger)gridView:(KKGridView *)gridView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
+@end
+
+@protocol KKGridViewDelegate <NSObject, UIScrollViewDelegate>
+@optional
+- (void)gridView:(KKGridView *)gridView didSelectItemAtIndexPath:(KKIndexPath *)indexPath;
+- (void)gridView:(KKGridView *)gridView didDeselectItemAtIndexPath:(KKIndexPath *)indexPath;
+- (KKIndexPath *)gridView:(KKGridView *)gridView willSelectItemAtIndexPath:(KKIndexPath *)indexPath;
+- (KKIndexPath *)gridView:(KKGridView *)gridView willDeselectItemAtIndexPath:(KKIndexPath *)indexPath;
+- (void)gridView:(KKGridView *)gridView willDisplayCell:(KKGridViewCell *)cell atIndexPath:(KKIndexPath *)indexPath;
+@end
@interface KKGridView : UIScrollView
@@ -47,7 +72,7 @@ typedef enum {
#pragma mark - Data Source and Delegate
@property (nonatomic, kk_weak) IBOutlet id <KKGridViewDataSource> dataSource;
-@property (nonatomic, kk_weak) IBOutlet id <KKGridViewDelegate> gridDelegate;
+@property (nonatomic, kk_weak) IBOutlet id <KKGridViewDelegate> delegate;
#pragma mark - Getters
@@ -90,30 +115,3 @@ typedef enum {
- (NSArray *)indexPathsForSelectedCells;
@end
-
-
-@protocol KKGridViewDataSource <NSObject>
-@required
-- (NSUInteger)gridView:(KKGridView *)gridView numberOfItemsInSection:(NSUInteger)section;
-- (KKGridViewCell *)gridView:(KKGridView *)gridView cellForItemAtIndexPath:(KKIndexPath *)indexPath;
-@optional
-- (NSUInteger)numberOfSectionsInGridView:(KKGridView *)gridView;
-- (NSString *)gridView:(KKGridView *)gridView titleForHeaderInSection:(NSUInteger)section;
-- (NSString *)gridView:(KKGridView *)gridView titleForFooterInSection:(NSUInteger)section;
-- (CGFloat)gridView:(KKGridView *)gridView heightForHeaderInSection:(NSUInteger)section;
-- (CGFloat)gridView:(KKGridView *)gridView heightForFooterInSection:(NSUInteger)section;
-- (UIView *)gridView:(KKGridView *)gridView viewForHeaderInSection:(NSUInteger)section;
-- (UIView *)gridView:(KKGridView *)gridView viewForFooterInSection:(NSUInteger)section;
-- (UIView *)gridView:(KKGridView *)gridView viewForRow:(NSUInteger)row inSection:(NSUInteger)section; // a row is compromised of however many cells fit in a column of a given section
-- (NSArray *)sectionIndexTitlesForGridView:(KKGridView *)gridView;
-- (NSInteger)gridView:(KKGridView *)gridView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
-@end
-
-@protocol KKGridViewDelegate <NSObject>
-@optional
-- (void)gridView:(KKGridView *)gridView didSelectItemAtIndexPath:(KKIndexPath *)indexPath;
-- (void)gridView:(KKGridView *)gridView didDeselectItemAtIndexPath:(KKIndexPath *)indexPath;
-- (KKIndexPath *)gridView:(KKGridView *)gridView willSelectItemAtIndexPath:(KKIndexPath *)indexPath;
-- (KKIndexPath *)gridView:(KKGridView *)gridView willDeselectItemAtIndexPath:(KKIndexPath *)indexPath;
-- (void)gridView:(KKGridView *)gridView willDisplayCell:(KKGridViewCell *)cell atIndexPath:(KKIndexPath *)indexPath;
-@end
View
24 KKGridView/KKGridView.m
@@ -22,7 +22,7 @@
NSUInteger itemCount;
};
-@interface KKGridView () <UIGestureRecognizerDelegate,UIScrollViewDelegate> {
+@interface KKGridView () <UIGestureRecognizerDelegate> {
// View-wrapper containers
NSMutableArray *_footerViews;
NSMutableArray *_rowViews;
@@ -135,7 +135,7 @@ + (void)animateIf:(BOOL)animated delay:(NSTimeInterval)delay options:(UIViewAnim
@implementation KKGridView
@synthesize dataSource = _dataSource;
-@synthesize gridDelegate = _gridDelegate;
+@dynamic delegate;
@synthesize allowsMultipleSelection = _allowsMultipleSelection;
@synthesize cellPadding = _cellPadding;
@synthesize cellSize = _cellSize;
@@ -242,12 +242,12 @@ - (void)setDataSource:(id<KKGridViewDataSource>)dataSource
}
}
-- (void)setGridDelegate:(id<KKGridViewDelegate>)gridDelegate
+- (void)setDelegate:(id<KKGridViewDelegate>)delegate
{
- if (gridDelegate != _gridDelegate)
+ if (delegate != self.delegate)
{
- _gridDelegate = gridDelegate;
-#define RESPONDS_TO(sel) [_gridDelegate respondsToSelector:@selector(sel)]
+ [super setDelegate:delegate];
+#define RESPONDS_TO(sel) [self.delegate respondsToSelector:@selector(sel)]
_delegateRespondsTo.didSelectItem = RESPONDS_TO(gridView:didSelectItemAtIndexPath:);
_delegateRespondsTo.willSelectItem = RESPONDS_TO(gridView:willSelectItemAtIndexPath:);
_delegateRespondsTo.didDeselectItem = RESPONDS_TO(gridView:didDeselectItemAtIndexPath:);
@@ -678,7 +678,7 @@ - (CGFloat)_sectionHeightsCombinedUpToRow:(NSUInteger)row inSection:(NSUInteger)
- (void)_displayCell:(KKGridViewCell *)cell atIndexPath:(KKIndexPath *)indexPath withAnimation:(KKGridViewAnimation)animation
{
if (_delegateRespondsTo.willDisplayCell) {
- [_gridDelegate gridView:self willDisplayCell:cell atIndexPath:indexPath];
+ [self.delegate gridView:self willDisplayCell:cell atIndexPath:indexPath];
}
if ([_updateStack hasUpdateForIndexPath:indexPath]) {
@@ -1410,7 +1410,7 @@ - (void)_selectItemAtIndexPath:(KKIndexPath *)indexPath
}
if (_delegateRespondsTo.didSelectItem) {
- [_gridDelegate gridView:self didSelectItemAtIndexPath:indexPath];
+ [self.delegate gridView:self didSelectItemAtIndexPath:indexPath];
}
}
@@ -1424,7 +1424,7 @@ - (void)_deselectAll
if(_delegateRespondsTo.willDeselectItem)
{
- [_gridDelegate gridView:self willDeselectItemAtIndexPath:indexPath];
+ [self.delegate gridView:self willDeselectItemAtIndexPath:indexPath];
}
}
@@ -1434,7 +1434,7 @@ - (void)_deselectAll
- (void)_deselectItemAtIndexPath:(KKIndexPath *)indexPath
{
if (_selectedIndexPaths.count > 0 && _delegateRespondsTo.willDeselectItem && indexPath.index != NSNotFound && indexPath.section != NSNotFound) {
- KKIndexPath *redirectedPath = [_gridDelegate gridView:self willDeselectItemAtIndexPath:indexPath];
+ KKIndexPath *redirectedPath = [self.delegate gridView:self willDeselectItemAtIndexPath:indexPath];
if (redirectedPath != nil && ![redirectedPath isEqual:indexPath]) {
indexPath = redirectedPath;
}
@@ -1447,7 +1447,7 @@ - (void)_deselectItemAtIndexPath:(KKIndexPath *)indexPath
}
if (_delegateRespondsTo.didDeselectItem) {
- [_gridDelegate gridView:self didDeselectItemAtIndexPath:indexPath];
+ [self.delegate gridView:self didDeselectItemAtIndexPath:indexPath];
}
}
@@ -1487,7 +1487,7 @@ - (void)_handleSelection:(UILongPressGestureRecognizer *)recognizer
KKIndexPath *indexPath = [self indexPathForItemAtPoint:locationInSelf];
if (state == UIGestureRecognizerStateEnded && _delegateRespondsTo.willSelectItem)
- indexPath = [_gridDelegate gridView:self willSelectItemAtIndexPath:indexPath];
+ indexPath = [self.delegate gridView:self willSelectItemAtIndexPath:indexPath];
if (!indexPath || indexPath.index == NSNotFound || indexPath.section == NSNotFound) {
[self _cancelHighlighting];
View
2  KKGridView/KKGridViewController.m
@@ -19,7 +19,7 @@ - (void)loadView
_gridView = [[KKGridView alloc] initWithFrame:self.view.bounds];
_gridView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
_gridView.dataSource = self;
- _gridView.gridDelegate = self;
+ _gridView.delegate = self;
self.view = _gridView;
}
Something went wrong with that request. Please try again.