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

Change scope and scroll to selected date #79

Closed
wimhaanstra opened this issue Sep 9, 2015 · 7 comments
Closed

Change scope and scroll to selected date #79

wimhaanstra opened this issue Sep 9, 2015 · 7 comments

Comments

@wimhaanstra
Copy link

I am trying out your component and after a couple of issues, I got most of it working.

What I am trying to achieve is the following:

  1. Display the .Month scope
  2. User selects a date
  3. Change scope of calendar to '.Week'
  4. Show selected date in the week scope

Step 1 to 3 works, animated, so that looks great, but I can't seem to be able to scroll the .Week scope to the right page.

I implemented my code like this:

func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) {
    if (calendar.scope == FSCalendarScope.Month) {
        calendar.setScope(FSCalendarScope.Week, animated: true)
        calendar.selectDate(date, scrollToDate: true)
    }
    else {
        self.navigationItem.rightBarButtonItem = nil;
    }
}

The problem with this method is that it crashes with the following error message:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 2386 when there are only 1560 sections in the collection view'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000104e7b9b5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010456ddeb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000104e7b81a +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00000001041bab72 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   UIKit                               0x00000001032988d0 -[UICollectionViewData numberOfItemsBeforeSection:] + 229
    5   UIKit                               0x000000010329897f -[UICollectionViewData globalIndexForItemAtIndexPath:] + 52
    6   UIKit                               0x000000010324ea98 -[UICollectionView cellForItemAtIndexPath:] + 111
    7   FSCalendar                          0x00000001027cb1e0 -[FSCalendar collectionView:shouldSelectItemAtIndexPath:] + 96
    8   FSCalendar                          0x00000001027cf7f2 -[FSCalendar selectDate:scrollToDate:forPlaceholder:] + 786
    9   FSCalendar                          0x00000001027cf4c9 -[FSCalendar selectDate:scrollToDate:] + 105
    10  Symagic                             0x000000010231fa78 _TFC7Symagic19MonthViewController8calendarfS0_FTGSQCSo10FSCalendar_13didSelectDateGSQCSo6NSDate__T_ + 568
    11  Symagic                             0x000000010231fca7 _TToFC7Symagic19MonthViewController8calendarfS0_FTGSQCSo10FSCalendar_13didSelectDateGSQCSo6NSDate__T_ + 71
    12  FSCalendar                          0x00000001027d12f1 -[FSCalendar didSelectDate:] + 369
    13  FSCalendar                          0x00000001027cae2f -[FSCalendar collectionView:didSelectItemAtIndexPath:] + 399
    14  UIKit                               0x000000010323e81b -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 684
    15  UIKit                               0x000000010325f6bd -[UICollectionView touchesEnded:withEvent:] + 574
    16  UIKit                               0x0000000102c57173 forwardTouchMethod + 349
    17  UIKit                               0x0000000102c5723c -[UIResponder touchesEnded:withEvent:] + 49
    18  UIKit                               0x0000000102c57173 forwardTouchMethod + 349
    19  UIKit                               0x0000000102c5723c -[UIResponder touchesEnded:withEvent:] + 49
    20  UIKit                               0x0000000102acb15f -[UIWindow _sendTouchesForEvent:] + 835
    21  UIKit                               0x0000000102acbd4d -[UIWindow sendEvent:] + 865
    22  UIKit                               0x0000000102a802ae -[UIApplication sendEvent:] + 263
    23  UIKit                               0x0000000102a5c36c _UIApplicationHandleEventQueue + 6693
    24  CoreFoundation                      0x0000000104da7b21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    25  CoreFoundation                      0x0000000104d9da4c __CFRunLoopDoSources0 + 556
    26  CoreFoundation                      0x0000000104d9cf03 __CFRunLoopRun + 867
    27  CoreFoundation                      0x0000000104d9c918 CFRunLoopRunSpecific + 488
    28  GraphicsServices                    0x0000000108461ad2 GSEventRunModal + 161
    29  UIKit                               0x0000000102a6199e UIApplicationMain + 171
    30  Symagic                             0x00000001022f970d main + 109
    31  libdyld.dylib                       0x0000000105b7e92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Any tips?

@WenchaoD
Copy link
Owner

WenchaoD commented Sep 9, 2015

Why did you select a date which had already been selected?

@wimhaanstra
Copy link
Author

Well, after the user selects the date, I want the scope to change and then scroll to the selected date, so I hoped I could force the week mode to scroll there.

@WenchaoD
Copy link
Owner

WenchaoD commented Sep 9, 2015

OK, I'll take a look at it tomorrow.

@wimhaanstra
Copy link
Author

The problem mentioned above isn't solely happening when selecting a date, but switching the scope of the calendar causes this error a lot of times for me.

The crash happens on the first line of:

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath

FSCalendarCell *cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath];

Switching to a Week scope, probably causes the indexPath to become invalid.

@WenchaoD
Copy link
Owner

Hi @depl0y
Can you use this as a temporary solusion?

- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
    if (calendar.scope == FSCalendarScopeMonth) {
        [calendar setScope:FSCalendarScopeWeek animated:YES];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            calendar.currentPage = date;
        });
    }
}

You should translate it to swift.
I know it's not an appropriate way, but I'll find one eventually.

@zjmdp
Copy link
Contributor

zjmdp commented Sep 16, 2015

The issue also puzzle me a lot..

@WenchaoD
Copy link
Owner

Fixed

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

No branches or pull requests

4 participants
@wimhaanstra @zjmdp @WenchaoD and others