0

I'm trying to reload FSCalendar using Dispatch main queue. it works fine but it causes the calendar to jump all the way back to 1970 how can i prevent this from happening? or set the date to current date again ? here is my code:

DispatchQueue.main.async {

    self.calendar.firstWeekday = 7
    self.calendar.locale = Locale(identifier: "fa_IR")
    self.calendar.select(Date())
    self.calendar.identifier = NSCalendar.Identifier.persian.rawValue
    self.calendar.reloadData()
}

btw this issue has nothing to do with Dispatch. reloading it in other forms causes the same problem too.

toddg
  • 2,863
  • 2
  • 18
  • 33
Farbod
  • 83
  • 1
  • 10
  • I've never used `FSCalendar`, but are you sure, `calendar.reloadData()` shouldn't happen after you change the data? To me it seems like the logical approach to first change the data, then reload the calendar. – Dávid Pásztor Sep 18 '17 at 19:26
  • @DávidPásztor tried that. Unfortunately, it doesn't fix the problem, – Farbod Sep 18 '17 at 19:30
  • 1
    A date in 1970 typically indicates that the actual date timestamp has been set to 0, or is missing. I haven't used FSCalendar but I'd check that it's getting a nonzero date value. – Tom Harrington Sep 18 '17 at 19:30
  • @TomHarrington that's not the case here. if that was the problem the calendar should still have problems when I remove reloadData(). but that doesn't happen – Farbod Sep 18 '17 at 19:35
  • @Farbod unless it's happening as a side-effect of calling `reloadData`. – Tom Harrington Sep 18 '17 at 19:37
  • @TomHarrington i checked it and timestamp isn't set to 0. – Farbod Sep 18 '17 at 20:03

1 Answers1

0

For current date you have to first get current month position. For that you must add two method of FSCalendarDelegate

func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition)   -> Bool {
    return monthPosition == .current
}

func calendar(_ calendar: FSCalendar, shouldDeselect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {

    return monthPosition == .current
}

Hope this will help you.

Yash Bhikadiya
  • 188
  • 1
  • 9