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 d89d7c2..bda3dcc 100644 --- a/TimesSquare/TSQCalendarView.m +++ b/TimesSquare/TSQCalendarView.m @@ -156,10 +156,24 @@ - (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 { - 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;