syshen / FlatDatePicker

MIT License
158 stars 23 forks source link

If SSFlatDatePicker's date is set to a month with 30 days and it is then set programmatically to the last day of a month with 31 days it crashes #9

Closed ghr1234 closed 10 years ago

ghr1234 commented 10 years ago

Thank you for publishing this widget. It loads much faster than the iOS6 UIDatePicker.

I believe there is a bug as described in the heading: I believe it tries to scroll the day to 31 which is 1 more than the number of items in the day scrollview when the scrollToItemAtIndexPath is invoked.

In this part of setDate: NSInteger currentDayIndex = [self.scrollerDay currentSelectedIndexPath].row; if (dateComponents.day != currentDayIndex) { [self.scrollerDay scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:dateComponents.day-1 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:animated]; }

I believe a fix is to add a line to the if section for month above like this: NSInteger currentMonthIndex = [self.scrollerMonth currentSelectedIndexPath].row; if (dateComponents.month != currentMonthIndex) { [self.scrollerMonth scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:dateComponents.month-1 inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:animated];

[self.scrollerDay reloadData]; // ghr1234

} Regards

ghr1234

syshen commented 10 years ago

fixed in Master