From 42a2b38c82c7ff42859fdf53b9a1568aa8dbfdf2 Mon Sep 17 00:00:00 2001 From: Stephen Christopher Date: Thu, 28 Mar 2013 20:10:46 -0400 Subject: [PATCH 1/3] scroll to exact row for date if pinToTop is not on. --- TimesSquare/TSQCalendarView.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TimesSquare/TSQCalendarView.m b/TimesSquare/TSQCalendarView.m index d89d7c2..7cf1f58 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -158,8 +158,14 @@ - (void)setSelectedDate:(NSDate *)newSelectedDate; - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated { - NSInteger section = [self sectionForDate:date]; - [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:animated]; + NSIndexPath *dateIndexPath; + if (self.pinsHeaderToTop) { + NSInteger section = [self sectionForDate:date]; + dateIndexPath = [NSIndexPath indexPathForRow:0 inSection:section]; + } else { + dateIndexPath = [self indexPathForRowAtDate:date]; + } + [self.tableView scrollToRowAtIndexPath:dateIndexPath atScrollPosition:UITableViewScrollPositionTop animated:animated]; } - (TSQCalendarMonthHeaderCell *)makeHeaderCellWithIdentifier:(NSString *)identifier; From 92f2d448dadb00358ec132e1ce154a97f673ab7f Mon Sep 17 00:00:00 2001 From: Stephen Christopher Date: Thu, 28 Mar 2013 20:11:32 -0400 Subject: [PATCH 2/3] add method to check whether date is currently visible. --- TimesSquare/TSQCalendarView.h | 9 +++++++++ TimesSquare/TSQCalendarView.m | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/TimesSquare/TSQCalendarView.h b/TimesSquare/TSQCalendarView.h index d6f0dab..ba5dda6 100644 --- a/TimesSquare/TSQCalendarView.h +++ b/TimesSquare/TSQCalendarView.h @@ -97,6 +97,15 @@ */ @property (nonatomic, strong) Class rowCellClass; +/** Returns whether the date's month is currently visible. + + Call this to check whether a given date is in the section currently scrolled to. + + @param date the date to be checked. + @return whether the date is the currently active section. + */ +- (BOOL)isDateVisible:(NSDate *)date; + /** Scrolls the receiver until the specified date month is completely visible. @param date A date that identifies the month that will be visible. diff --git a/TimesSquare/TSQCalendarView.m b/TimesSquare/TSQCalendarView.m index 7cf1f58..aa49075 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -156,6 +156,14 @@ - (void)setSelectedDate:(NSDate *)newSelectedDate; } } +- (BOOL)isDateVisible:(NSDate *)date +{ + NSIndexPath *dateIndexPath = [self indexPathForRowAtDate:date]; + NSArray *visibleRows = self.tableView.indexPathsForVisibleRows; + if ([visibleRows containsObject:dateIndexPath]) return YES; + return NO; +} + - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated { NSIndexPath *dateIndexPath; From 410c65ad3ca19711368c1359db2c9661e2763e07 Mon Sep 17 00:00:00 2001 From: Stephen Christopher Date: Fri, 19 Apr 2013 13:14:07 -0400 Subject: [PATCH 3/3] fix whitespace. --- TimesSquare/TSQCalendarView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TimesSquare/TSQCalendarView.m b/TimesSquare/TSQCalendarView.m index aa49075..bda3dcc 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -173,7 +173,7 @@ - (void)scrollToDate:(NSDate *)date animated:(BOOL)animated } else { dateIndexPath = [self indexPathForRowAtDate:date]; } - [self.tableView scrollToRowAtIndexPath:dateIndexPath atScrollPosition:UITableViewScrollPositionTop animated:animated]; + [self.tableView scrollToRowAtIndexPath:dateIndexPath atScrollPosition:UITableViewScrollPositionTop animated:animated]; } - (TSQCalendarMonthHeaderCell *)makeHeaderCellWithIdentifier:(NSString *)identifier;