JTAppleCalendar Common Questions #1

By: Patch the Code

26   0   2492

Uploaded on 07/16/2017

This video solves some of the common questions of the JTAppleCalendar library for your Swift iOS project. With this library, framework, view, makes building Calendars is easy.

JTAppleCalendar can be found on Cocoapods here - https://cocoapods.org/pods/JTAppleCalendar
Githublink - https://github.com/patchthecode/JTAppleCalendar
UserCreated JTAppleCalendar link1 - https://github.com/patchthecode/JTAppleCalendar/issues/2
UserCreated JTAppleCalendar link2 - https://github.com/patchthecode/JTAppleCalendar/issues/216

Comments (4):

By anonymous    2017-10-08

I m using below video as a reference for JTAppleCalendar.

https://www.youtube.com/watch?v=CQNotydm58s&t=19s

I place the code in viewDidAppear Event and I got below error msg:

Problem:
error msg 1: Thread: EXC_BAD_ACCESS(code=EXC_i386_GPFLT) for below.

override open func layoutSubviews() {
    super.layoutSubviews()
    if !delayedExecutionClosure.isEmpty, isCalendarLayoutLoaded {
        executeDelayedTasks()
    }
}

The Code is as follows:

import UIKit
import JTAppleCalendar

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    DispatchQueue.global().asyncAfter(deadline: .now()) {
        let serverObjects = self.getServerEvents()
        for(date, event) in serverObjects {
            let stringDate = self.formatter.string(from: date)
            self.eventsFromTheServer[stringDate] = event
        }

        DispatchQueue.main.async{
            self.calendarView.reloadData()
        }
    }

    calendarView.minimumLineSpacing = 0
    calendarView.minimumInteritemSpacing = 0

    calendarView.scrollToDate(Date(), animateScroll: true)
    calendarView.selectDates([Date()])

    calendarView.visibleDates { dateSegment in
        self.setupCalendarView(dateSegment: dateSegment)
    }
}

Error Msg 2, when placing in viewDidLoad Event:

error Msg :

Attempt to present LoginViewController on ( this project Name ) whose view is not in the window hierarchy!

override func viewDidLoad() {
        super.viewDidLoad()


// Do any additional setup after loading the view.


let defaults = UserDefaults.standard



if defaults.object(forKey: "SessionToken") == nil {


let VC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController


self.dismiss(animated: false)

self.present(VC,animated:false)


}else {




 //-- have session token show below:
 DispatchQueue.global().asyncAfter(deadline: .now()) {

   let serverObjects = self.getServerEvents()

  for(date, event) in serverObjects {

  let stringDate = self.formatter.string(from: date)

     self.eventsFromTheServer[stringDate] = event

    }

 DispatchQueue.main.async{

      self.calendarView.reloadData()
 }

}


   calendarView.minimumLineSpacing = 0
   calendarView.minimumInteritemSpacing = 0

   calendarView.scrollToDate(Date(), animateScroll: true)
   calendarView.selectDates([Date()])


   calendarView.visibleDates { dateSegment in

  self.setupCalendarView(dateSegment: dateSegment)
   }

        }
    }

Please help.

Thanks

Original Thread

By anonymous    2017-10-22

@Vasya2014 this [video](https://www.youtube.com/watch?v=CQNotydm58s) has an example. checked it out yet?

Original Thread

By anonymous    2017-11-06

hi newBiew in JTAppleCalendar. I have following this link for creating a Calendar base on JTAppleCalendar. https://www.youtube.com/watch?v=CQNotydm58s&index=6&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q

I could not figure how to get a date after user press the date on the Calendar.

Here the code:
in the didSelectDate. The date return is always one day behind??

This is what I wanted to achieve. When user tap on the date on the calendar, I want to get the date and use this date to request data from the server,

extension MyCalendar: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {

    func configureCalendar( _ calendar:JTAppleCalendarView) ->ConfigurationParameters{

        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let startDate = formatter.date(from: "2017 01 01")!
        let endDate = formatter.date(from: "2027 12 31")!        

        let parameters = ConfigurationParameters(startDate : startDate, endDate: endDate)          
        return parameters

    }


  func calendar( _ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell{


        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell

        cell.dateLabel.text = cellState.text

        configureCell(cell:cell, cellState: cellState)

        return cell

    }


    //------------ selected item

    func calendar( _ calendar: JTAppleCalendarView, didSelectDate date: Date, cell:JTAppleCell?, cellState:CellState){

        // cell is option
        configureCell(cell: cell, cellState: cellState)

       //prolem:
        let strdate = cellState.date

    }


    func calendar( _ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell:JTAppleCell?, cellState:CellState){

        // cell is option
        configureCell(cell: cell, cellState: cellState)

    }

   func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {

       setupCalendarView(dateSegment: visibleDates)

    }

}

Please help,

Thanks

Original Thread

By anonymous    2017-11-20

hi newBiew in JTAppleCalendar. I follow this link for JTAppleCalendar. https://www.youtube.com/watch?v=CQNotydm58s&index=6&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q

I have this Problem:

How to I show calendar when user click a button to change monthView to WeekView or from week View to month View

How to I change the calendar size programmatically for CalendarView and mainStack as they have constrains?
I believe I need to handle configureCalendar as below but how to change programmatically month view to week view vice versa.
I have a stack (Call it mainStack) which used to contain CalendarView

Layout for the Calendar view :

@IBOutlet weak var CalendarView : JTAppleCalendarView!
@IBOutlet weak var mainStack: UIStackView!

extension MyCalendar: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {

    func configureCalendar( _ calendar:JTAppleCalendarView) ->ConfigurationParameters{

        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let startDate = formatter.date(from: "2017 01 01")!
        let endDate = formatter.date(from: "2027 12 31")!        

        //-- how to set these "

       1) Full calendar view

        let parameters = ConfigurationParameters(startDate : startDate, endDate: endDate)          
        return parameters


       2) for week view
        let parameters = ConfigurationParameters(startDate : startDate, endDate: endDate, numberOfRows:1)      

        return parameters

    }


  func calendar( _ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell{


        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell

        cell.dateLabel.text = cellState.text

        configureCell(cell:cell, cellState: cellState)

        return cell

    }


    //------------ selected item

    func calendar( _ calendar: JTAppleCalendarView, didSelectDate date: Date, cell:JTAppleCell?, cellState:CellState){

        configureCell(cell: cell, cellState: cellState)     

    }


    func calendar( _ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell:JTAppleCell?, cellState:CellState){

              configureCell(cell: cell, cellState: cellState)

    }

   func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {

       setupCalendarView(dateSegment: visibleDates)

    }

}

Please help.

Thanks

Original Thread

Popular Videos 1234

Submit Your Video

If you have some great dev videos to share, please fill out this form.