From 4dac33b54bf8a9308356f9a4bb9e3e2b13fd1834 Mon Sep 17 00:00:00 2001 From: Mathieu Baron Date: Tue, 14 Jun 2016 11:56:13 -0400 Subject: [PATCH] scrollToIndex: fix when previousButton index is larger than current button count --- Pod/Classes/MRGPagerTitleStrip.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/MRGPagerTitleStrip.m b/Pod/Classes/MRGPagerTitleStrip.m index 16ebedb..175bfba 100644 --- a/Pod/Classes/MRGPagerTitleStrip.m +++ b/Pod/Classes/MRGPagerTitleStrip.m @@ -197,10 +197,10 @@ - (void)scrollToIndex:(CGFloat)index animated:(BOOL)animated { if ([self.buttons count] > 0 && (self.scrollView.contentSize.width > CGRectGetWidth(self.scrollView.bounds))) { CGFloat offset = 0; - NSInteger prevButtonIndex = MAX(floorf(index), 0); + NSInteger prevButtonIndex = MAX(MIN(floorf(index), [self.buttons count]), 0); NSInteger nextButtonIndex = MIN(ceilf(index), [self.buttons count] - 1); - for (NSInteger ii = 0, count = MIN(prevButtonIndex, [self.buttons count]); ii < count; ++ii) { + for (NSInteger ii = 0, count = prevButtonIndex; ii < count; ++ii) { offset += CGRectGetWidth([self.buttons[ii] bounds]); offset += self.separatorSize.width; }