Skip to content

Commit

Permalink
Use internal delegate instead of overriding existing delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Oct 12, 2018
1 parent d1476b2 commit 4a4175b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
FSCalendarOrientationPortrait
};

@interface FSCalendar ()<FSCalendarCollectionViewDataSource,FSCalendarCollectionViewDelegate,UIGestureRecognizerDelegate>
@interface FSCalendar ()<UICollectionViewDataSource,UICollectionViewDelegate,FSCalendarCollectionViewInternalDelegate,UIGestureRecognizerDelegate>
{
NSMutableArray *_selectedDates;
}
Expand Down Expand Up @@ -208,6 +208,7 @@ - (void)initialize
collectionViewLayout:collectionViewLayout];
collectionView.dataSource = self;
collectionView.delegate = self;
collectionView.internalDelegate = self;
collectionView.backgroundColor = [UIColor clearColor];
collectionView.pagingEnabled = YES;
collectionView.showsHorizontalScrollIndicator = NO;
Expand Down
8 changes: 2 additions & 6 deletions FSCalendar/FSCalendarCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
#import <UIKit/UIKit.h>
@class FSCalendarCollectionView;

@protocol FSCalendarCollectionViewDataSource <UICollectionViewDataSource>

@end

@protocol FSCalendarCollectionViewDelegate <UICollectionViewDelegate>
@protocol FSCalendarCollectionViewInternalDelegate <UICollectionViewDelegate>

@optional
- (void)collectionViewDidFinishLayoutSubviews:(FSCalendarCollectionView *)collectionView;
Expand All @@ -22,7 +19,6 @@

@interface FSCalendarCollectionView : UICollectionView

@property (assign, nonatomic) id<FSCalendarCollectionViewDataSource> dataSource;
@property (assign, nonatomic) id<FSCalendarCollectionViewDelegate> delegate;
@property (weak, nonatomic) id<FSCalendarCollectionViewInternalDelegate> internalDelegate;

@end
5 changes: 2 additions & 3 deletions FSCalendar/FSCalendarCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ - (void)commonInit;
@implementation FSCalendarCollectionView

@synthesize scrollsToTop = _scrollsToTop, contentInset = _contentInset;
@dynamic dataSource, delegate;

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
Expand Down Expand Up @@ -52,8 +51,8 @@ - (void)commonInit
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.delegate && [self.delegate respondsToSelector:@selector(collectionViewDidFinishLayoutSubviews:)]) {
[self.delegate collectionViewDidFinishLayoutSubviews:self];
if (self.internalDelegate && [self.internalDelegate respondsToSelector:@selector(collectionViewDidFinishLayoutSubviews:)]) {
[self.internalDelegate collectionViewDidFinishLayoutSubviews:self];
}
}

Expand Down
2 changes: 1 addition & 1 deletion FSCalendar/FSCalendarHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "FSCalendarCollectionView.h"
#import "FSCalendarDynamicHeader.h"

@interface FSCalendarHeaderView ()<FSCalendarCollectionViewDataSource,FSCalendarCollectionViewDelegate>
@interface FSCalendarHeaderView ()<UICollectionViewDataSource,UICollectionViewDelegate,FSCalendarCollectionViewInternalDelegate>

- (void)scrollToOffset:(CGFloat)scrollOffset animated:(BOOL)animated;
- (void)configureCell:(FSCalendarHeaderCell *)cell atIndexPath:(NSIndexPath *)indexPath;
Expand Down

0 comments on commit 4a4175b

Please sign in to comment.