JTAppleCalendar: Bug on mutiple selection

Hi,

It will be hard to explain it in english, but I will give a try ;P.

I have a application with a filter on the top in which I can select a whole week for example, I also have 2 buttons on the top in which I can go to the next week or to the previous week. Here is my screen:

Default Screen

In order to to go to the previous week or to the next week, I deselect the current selected week and select the next one, everything works fine when I press the buttons slowly. However, we I press the next or the previous repeatedly, at some point, the selector become crazy, and I lost the reference of the weeks, or it gives an weird crash (fatal error: Index out of range).

The crash breakpoint: screen shot 2016-07-06 at 11 30 13 am

And the crazy selection (It should be selecting from 10-16, but it’s not selecting the 12, and selecting the 17): slack for ios upload-1

Here is my code:


    @IBAction func calendarPreviousButtonPressed(sender: AnyObject) {

        //an array with the last selected dates
        var referenceDate = currentSelectedDates.getElement(0)!
        unselectSelectedDates()

        //An enum that indicates the current filter been applied.
        switch currentDateFilter {
        case .monthly:
            referenceDate = referenceDate.sameDayOnMonth(-1)
            currentSelectedDates = referenceDate.daysOnThisMonth()
        case .weekly:
            //returns the same day of the week, from the next week, for example if today is 01/07/2016, it will returns the 08/07/2016
            referenceDate = referenceDate.sameDayOnWeek(-1)
            //returns an array with all the dates from the current week.
            currentSelectedDates = referenceDate.daysOnThisWeek()
        case .today:
            changeDateFilter(.day)
            currentSelectedDates = [referenceDate]
        case .day:
            referenceDate = referenceDate.addDay(-1)
            currentSelectedDates = [referenceDate]

        }


        self.calendarView.scrollToDate(self.currentSelectedDates[0], animateScroll: true) {
            [unowned self] in
            self.calendarView.selectDates(self.currentSelectedDates, triggerSelectionDelegate: true)
        }

    }

The unselectSelectedDates function:

    func unselectSelectedDates() {
        let selectedDates = self.calendarView.selectedDates
        calendarView.selectDates(selectedDates)
    }

After further investigation, I figured out that the unselect and selection delegate methods, are called asynchronously, and it could be causing the problem, but I couldn’t find a easy solution for that, do you have any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

looking into it now.