From a90d22886e31a5e69c122813e716929c658c5cc5 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Tue, 26 Feb 2013 14:25:30 +0800 Subject: [PATCH] Change Delegate to @optional --- .../UITableView+ZGPullDrag.h | 2 ++ .../UITableView+ZGPullDrag.m | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ZGPullDragTableViewClass/UITableView+ZGPullDrag.h b/ZGPullDragTableViewClass/UITableView+ZGPullDrag.h index 88bb31f..2c3b0c7 100644 --- a/ZGPullDragTableViewClass/UITableView+ZGPullDrag.h +++ b/ZGPullDragTableViewClass/UITableView+ZGPullDrag.h @@ -9,11 +9,13 @@ #import @protocol ZGDragViewDelegate +@optional - (void)dragView:(UIView *)dragView Show:(CGFloat )showPixels ofTotal:(CGFloat )totalPixels; - (void)dragView:(UIView *)dragView hangForCompletionBlock:(void (^)())completed; @end @protocol ZGPullViewDelegate +@optional - (void)pullView:(UIView *)pullView Show:(CGFloat )shownPixels ofTotal:(CGFloat )totalPixels; - (void)pullView:(UIView *)pullView hangForCompletionBlock:(void (^)())completed; @end diff --git a/ZGPullDragTableViewClass/UITableView+ZGPullDrag.m b/ZGPullDragTableViewClass/UITableView+ZGPullDrag.m index b928f05..f5bdc70 100644 --- a/ZGPullDragTableViewClass/UITableView+ZGPullDrag.m +++ b/ZGPullDragTableViewClass/UITableView+ZGPullDrag.m @@ -131,38 +131,46 @@ static char UITableViewZGDragView; } - (void)pullViewHandler:(CGFloat )visiblePixels{ - [self.ZGPullViewDelegate pullView:self.pullView Show:visiblePixels ofTotal:self.pullView.frame.size.height]; + if ([self.ZGPullViewDelegate respondsToSelector:@selector(pullView:Show:ofTotal:)]) { + [self.ZGPullViewDelegate pullView:self.pullView Show:visiblePixels ofTotal:self.pullView.frame.size.height]; + } if (visiblePixels>self.pullView.frame.size.height && !self.isDragging) { [UIView animateWithDuration:0.1 animations:^{ self.contentInset = UIEdgeInsetsMake(self.pullView.frame.size.height, 0, 0, 0); } completion:^(BOOL finished) { - [self.ZGPullViewDelegate pullView:self.pullView hangForCompletionBlock:^{ - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - [UIView animateWithDuration:0.2 animations:^{ - self.contentInset = UIEdgeInsetsZero; + if ([self.ZGPullViewDelegate respondsToSelector:@selector(pullView:hangForCompletionBlock:)]) { + [self.ZGPullViewDelegate pullView:self.pullView hangForCompletionBlock:^{ + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [UIView animateWithDuration:0.2 animations:^{ + self.contentInset = UIEdgeInsetsZero; + }]; }]; }]; - }]; + } }]; } } - (void)dragViewHandler:(CGFloat )visiblePixels{ - [self.ZGDragViewDelegate dragView:self.dragView Show:visiblePixels ofTotal:self.dragView.frame.size.height]; + if ([self.ZGDragViewDelegate respondsToSelector:@selector(dragView:Show:ofTotal:)]) { + [self.ZGDragViewDelegate dragView:self.dragView Show:visiblePixels ofTotal:self.dragView.frame.size.height]; + } if (visiblePixels>self.dragView.frame.size.height && !self.isDragging) { [UIView animateWithDuration:0.1 animations:^{ self.contentInset = UIEdgeInsetsMake(0, 0, self.dragView.frame.size.height, 0); } completion:^(BOOL finished) { - [self.ZGDragViewDelegate dragView:self.dragView hangForCompletionBlock:^{ - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - [UIView animateWithDuration:0.2 animations:^{ - self.contentInset = UIEdgeInsetsZero; + if ([self.ZGDragViewDelegate respondsToSelector:@selector(dragView:hangForCompletionBlock:)]) { + [self.ZGDragViewDelegate dragView:self.dragView hangForCompletionBlock:^{ + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [UIView animateWithDuration:0.2 animations:^{ + self.contentInset = UIEdgeInsetsZero; + }]; }]; }]; - }]; + } }]; } }