Reputation: 157
Hi I'm trying to show the JTAppleCalendar with the current date selected but I would like it not to trigger the isSelected because I would like to show a timepicker when the user actually selects a date instead of being triggered when the Calendar loads with the current date
Current code when the a cell is selected
func handleCellSelected(view: JTAppleCell?, cellState: CellState){
guard let validCell = view as? CalendarCell else {return}
if validCell.isSelected{
validCell.selectedView.isHidden = false
if remindMeOnDay.isOn{
self.formatter.dateFormat = "yyyy MMMM dd"
if userPickedDate{
dateSelected.text = formatter.string(for:userDate)
SelectTime(sender: validCell)
//self.dateSelected.text = self.formatter.string(from: cellState.date)
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300), execute: {
self.updateTableView(tableView: self.tableView)
})
}
}
userPickedDate = true
}else {
validCell.selectedView.isHidden = true
}
}
The trigger Code
@IBAction func remindMeOnDaySwitch(_ sender: UISwitch?) {
let date = Date()
self.tableView.beginUpdates()
tableView.reloadData()
//Shows the calendar with current date selected
if remindMeOnDay.isOn{
calendarView.scrollToDate(date)
self.calendarView.selectDates([NSDate() as Date])
//self.calendarView.selectDates([NSDate() as Date])
if !checkForNotificationAccess(){
notificationAlert()
remindMeOnDay.isOn = false
}
}
if !remindMeOnDay.isOn {
userDate = date
userPickedDate = false
}
self.tableView.endUpdates()
}
Upvotes: 1
Views: 1298
Reputation: 16720
This can be done with the following code:
calendarView.selectDates([Date()], triggerSelectionDelegate: false)
Upvotes: 1