1

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()
}

The result I'm getting

CFRJ
  • 157
  • 1
  • 12

1 Answers1

1

This can be done with the following code:

calendarView.selectDates([Date()], triggerSelectionDelegate: false)
Just a coder
  • 15,480
  • 16
  • 85
  • 138
  • Hi, so I changed the selectDates code but validCell.isSelected is still true which in turn triggers my timepicker to launch. ideas? – CFRJ Aug 04 '17 at 19:54
  • Well if you `timePicker` launch depends on whether or not the cell is selected, then how do you wish to differentiate between an user selection VS a programatic selection? – Just a coder Aug 04 '17 at 20:01
  • hmm I don't know, would it be possible to add something like a hidden view on top of the calendar cell or something that would trigger the timepicker? I just thought there would be an easy way to launch the calendar with the current date selected and then trigger something else when the user picked a date – CFRJ Aug 04 '17 at 20:04
  • there is. I think youre doing something complicated -> can you join me here https://gitter.im/patchthecode/JTAppleCalendar – Just a coder Aug 04 '17 at 21:48
  • Hey I got it working, kinda, I set the userpickeddate = true inside de didselectdate function. Now every date works as expected except the current date selected which require a double tap and the launches two timepickers. – CFRJ Aug 04 '17 at 22:39
  • I added an upgrate for you. Now it is possible to check to see user selection VS a programatic selection. Now you can check `cellState.selectionChangedProgramatically`. Let me know if this works for you. Currently the upgrade is on master branch. Follow the instructions [Here](https://github.com/patchthecode/JTAppleCalendar/wiki/Common-Questions) to test it. Let me know if this works for you. – Just a coder Aug 10 '17 at 14:22