Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting fromDate and toDate has no effect #20

Open
mrbagels opened this issue Jan 15, 2014 · 4 comments
Open

Setting fromDate and toDate has no effect #20

mrbagels opened this issue Jan 15, 2014 · 4 comments

Comments

@mrbagels
Copy link

Here is my code after initializing MNCaldendarView:

NSDate *todayDate = [NSDate date];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:+6];
NSDate *afterSixMonths = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:todayDate options:0];

self.calendarView.fromDate = [NSDate date];
self.calendarView.toDate = afterSixMonths;

As you can see, I am basically wanting to have the calendar only show the next 6 months instead of the next 4 years.

The calendar view seems to basically be ignoring this.

If I go into the commonInit method in MNCalendarView.m and manually change the code from this:

self.toDate     = [self.fromDate dateByAddingTimeInterval:MN_YEAR * 4];

to:

self.toDate     = [self.fromDate dateByAddingTimeInterval:MN_YEAR * 0.5]; //<-------- Multiplied by 0.5 to get 6 months

I can scroll it up so that it shows the full final 6 month, but then it snaps back into place for the month above it. I am assuming it just isn't recognizing that this is now the new "last month". I also can't find the area where it detects the last month, so I am searching for that still.

Any insight would be great, thanks!

@abbood
Copy link

abbood commented Mar 27, 2014

yeah same problem here

@abbood
Copy link

abbood commented Mar 27, 2014

oh I figured it out @kbegeman .. you basically just have to call reload data.. this is my code (using NiceDate):

MNCalendarView *calendarView = [[MNCalendarView alloc] initWithFrame:self.view.bounds];
calendarView.delegate = self;

NiceDate *previousDate = [NiceDate niceDate];
previousDate.year--;
calendarView.fromDate = previousDate.date;

NiceDate *futureDate = [NiceDate niceDate];
futureDate.year++;
calendarView.toDate = futureDate.date;

calendarView.selectedDate = [NSDate date];
[calendarView reloadData];

@abbood
Copy link

abbood commented Mar 27, 2014

but i thought it would automatically scroll to the selected date! lol anyone knows how to do that?

@RyanCopley
Copy link

-(void)scrollToTodaysMonth {
     NSDateComponents *components_ = [[NSCalendar currentCalendar] components:         NSCalendarUnitMonth fromDate:[NSDate date]];
    NSInteger month = [components_ month]-1;
    [calendar.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:month] atScrollPosition:PSTCollectionViewScrollPositionTop animated:YES];
}

I call that function to scroll to todays day, you can modify it to the selected date, etc.

(Also-- watch out, I use a subclassed version of UICollectionView called PSTCollectionView, but you can replace PST with UI just fine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants