WenchaoD / FSCalendar

A fully customizable iOS calendar library, compatible with Objective-C and Swift
MIT License
10.6k stars 1.94k forks source link

didSelect Not Getting Called #1051

Open raginggoat opened 5 years ago

raginggoat commented 5 years ago

I am able to select dates just fine when tapping on a date. My issue is happening when using a date picker to select a date. It selects the date on the calendar but the didSelect method doesn't get called.

@objc func dismissKeyboard() {  
        for date in self.calendarView.selectedDates {
            self.calendarView.deselect(date)
        }

        let dateFormatter = DateFormatter()
        dateFormatter.dateStyle = .medium
        dateFormatter.timeStyle = .none
        let startDate = dateFormatter.date(from: self.startDateField.text!)
        if startDate != nil {
            self.enteredStartDate = startDate
            self.calendarView.select(startDate, scrollToDate: false)
        }

        self.startDateField.resignFirstResponder()
    }
func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
        if date <= Date() {
            return monthPosition == .current
        } else {
            return false
        }
    }
func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
        print("didSelect")
        if self.enteredStartDate == nil {
            self.enteredStartDate = Date()
        }

        calendar.deselect(self.enteredStartDate!)
        self.enteredStartDate = date
        saveStartDateToFirestore()
    }
Husseinhj commented 5 years ago

@raginggoat

Check the issue #99, Yes didSelect event do not be invoked when by calling selectDate method.

The simple way to call the didSelect function after call selectDate method, Like this:


@objc func dismissKeyboard() {  
    for date in self.calendarView.selectedDates {
        self.calendarView.deselect(date)
    }

    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .medium
    dateFormatter.timeStyle = .none
    let startDate = dateFormatter.date(from: self.startDateField.text!)
    if startDate != nil {
        self.enteredStartDate = startDate
        self.calendarView.select(startDate, scrollToDate: false)

        //Call after select method.
        self.calendar(self.calendar, didSelect: startDate, at: .current)
    }

    self.startDateField.resignFirstResponder()
}