ios - JTAppleCalendar with event in tableview -
i have bit complicated question explain, try precise can. building calendar (i'm using jtapplecalendar) notes. i'm trying achieve show calendar , beneath tableview list notes specific day. note stored in core data. have 2 entity: agendanotes agendanotedates
agendanotes has 1 many relationship agendanotedates (so every note can have multiple dates)
the point note dates , show beneath selected date list of note belonging specific date. each time user select day/date tableview update , show note day if exist or simple text if there no note.
until have set calendar:
@iboutlet weak var tableview: uitableview! @iboutlet weak var calendar: jtapplecalendarview! var eventsfromtheserver: [string:agendaevent] = [:] override func viewdidload() { super.viewdidload() dispatchqueue.global().asyncafter(deadline: .now()) { let serverobjects = self.getserverevents() (date, event) in serverobjects { let stringdate = self.formatter.string(from: date) self.eventsfromtheserver[stringdate] = event } dispatchqueue.main.async { self.calendar.reloaddata() } }
here handle cell selection:
func handlecellselection(cell: calendarcell, cellstate: cellstate) { let celldatestring = formatter.string(from: cellstate.date) (title, event) in eventsfromtheserver { if title == celldatestring { func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { // dequeue cell let cell = tableview.dequeuereusablecell(withidentifier: "calendaragendacell", for: indexpath) as! calendaragendacell //fetch model object display configuringcell(cell: cell, indexpath: indexpath) // return cell return cell } } } } func configuringcell(cell: calendaragendacell, indexpath: indexpath) { let myevent = myevents[indexpath.row] cell.configurecell(agendaevent: myevent) } // cell configuration functions func configurecell(cell: jtapplecell?, cellstate: cellstate) { guard let mycustomcell = cell as? calendarcell else {return} handlecellselection(cell: mycustomcell, cellstate: cellstate) handlecellevents(cell: mycustomcell, cellstate: cellstate) } func handlecellevents(cell: calendarcell, cellstate: cellstate) { // $0 index value events server array, closure says key matches cellstate, statement says event dot view hidden if event server not contain value formatter.dateformat = "dd mm yyyy" cell.dotimage.ishidden = !eventsfromtheserver.contains { $0.key == formatter.string(from: cellstate.date)} } func calendar(_ calendar: jtapplecalendarview, didselectdate date: date, cell: jtapplecell?, cellstate: cellstate) { selecteddate = date configurecell(cell: cell, cellstate: cellstate) calendar.reloaddata() tableview.reloaddata() }
and here extension values:
extension calendarvc { func getserverevents() -> [date:agendaevent] { var myevent: agendaevent! var eventdate: date! event in myevents { date in (event.agendadates as? set<agendadate>)! { let eventdates = date.agendadates eventtitle = event.agendatitle eventdesc = event.agendadescription eventdate = eventdates myevent = event } } formatter.dateformat = "dd mm yyyy" let eventdatestring = formatter.string(from: eventdate) formatter.dateformat = "dd mm yyyy" return [formatter.date(from: eventdatestring)! : myevent ] }
}
obviously have implemented jtapplecalendarviewdatasource , jtapplecalendarviewdelegate.
this first time i'm using jtapplecalendar , haven't been able find in doc. unfortunately seems cannot understand mistake is, small pointing in right direction appreciated!
Comments
Post a Comment