Jtapplecalendar: reloadData does not call willDisplayCell

Created on 21 Mar 2017  Â·  7Comments  Â·  Source: patchthecode/JTAppleCalendar

Currently, calling .reloadData() on my calendar view does not call willDisplayCell in my delegate.

In my code, I call this:

self.mainVw?.calVw.deselectAllDates(triggerSelectionDelegate: false)
self.mainVw?.startDate = nil
self.mainVw?.endDate = nil
self.mainVw?.calVw.reloadData()

Putting a breakpoint on that reload call, I then place breakpoints in my delegate method:

func calendar(_ calendar: JTAppleCalendarView, willDisplayCell cell: JTAppleDayCellView, date: Date, cellState: CellState) {
    let calCell = cell as! MyCalendarCell
    self.styleCalCell(calCell: calCell, cellState: cellState)
}

The code never reaches willDisplayCell after reloadData, which I need so my newly deselected cells will display properly without highlighting. It looks like reload should be set up to call willDisplayCell from your source, but it doesn't seem to be calling it.

Wont Fix

Most helpful comment

For anyone that runs across this issue while it's being fixed, the workaround is to just grab the selected dates or dates you want to reload prior to doing any manipulation, do your manipulation, then reload those specific dates.

let selectedDates = self.calVw.selectedDates
self.calVw.deselectAllDates(triggerSelectionDelegate: false)
//Other things
self.calVw.reloadDates(selectedDates)

All 7 comments

Ok, this is odd. What version of the library are you using?

This tends to happen if you recently upgraded from a previous version of the calendar.
And the new versions willDisplayCell function has been renamed to something else.
Therefore it will not be called, because you do not have the correct name.

I am using version 6.1.5. This is the version I started with with this project. If I call reloadDates it does hit my willDisplayCell, but not with reloadData or reloadData with anchor.

ok, then i must have had some error introduced somewhere.
Can you check the master branch and see if the error is already fixed there?

You can test the master branch by Following the quick instructions here

If it is still not fixed on master branch, then i will look into this after work.

Tried master, but it bombs on this line in JTAppleCalendarView:

    /// Enables/Disables multiple selection on JTAppleCalendar
    open var allowsMultipleSelection: Bool = false {
        didSet {
            calendarView.allowsMultipleSelection = allowsMultipleSelection
        }
    }

Getting a nil error:

fatal error: unexpectedly found nil while unwrapping an Optional value

For anyone that runs across this issue while it's being fixed, the workaround is to just grab the selected dates or dates you want to reload prior to doing any manipulation, do your manipulation, then reload those specific dates.

let selectedDates = self.calVw.selectedDates
self.calVw.deselectAllDates(triggerSelectionDelegate: false)
//Other things
self.calVw.reloadDates(selectedDates)

Thanks for the investigation. I'll look into this after work.

Added the Wont Fix tag to this.
Will close this as it is resolved in version 7.0
Release time will be in about 1 week

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kevinw14 picture Kevinw14  Â·  3Comments

PedroAnibarro1 picture PedroAnibarro1  Â·  5Comments

Fatalution picture Fatalution  Â·  3Comments

dimitris-c picture dimitris-c  Â·  5Comments

blinkmeoff picture blinkmeoff  Â·  3Comments