Closed yillivs closed 8 years ago
Does your issue look something like this?
Yes exactly like that.
If it looks like that then, did you follow the step in the tutorial which has this code?
extension ViewController: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {
// Setting up manditory protocol method
func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar) {
// You can set your date using NSDate() or NSDateFormatter. Your choice.
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy MM dd"
let firstDate = formatter.dateFromString("2016 01 05")
let secondDate = NSDate()
let numberOfRows = 6
let aCalendar = NSCalendar.currentCalendar() // Properly configure your calendar to your time zone here
return (startDate: firstDate!, endDate: secondDate, numberOfRows: numberOfRows, calendar: aCalendar)
}
}
Remember, your calendar has to conform to the dataSource protocol. If it does not conform to the datasource, XCode will scream at you :)
I believe so, I wrote this in the class same class as that manages the calendar view.
func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar){
let formatter = NSDateFormatter()//access to date formatter method
formatter.dateFormat = "yyyy MM dd"
let firstDate = formatter.dateFromString("2016 05 10")
let secondDate = NSDate()
let numberOfRows = 6
let aCalendar = NSCalendar.currentCalendar()
//return logical calendar for current user
return(startDate: firstDate!, endDate: secondDate, numberOfRows: numberOfRows, calendar: aCalendar)
}
But examining it currently I notice that I missed this line.
extension ViewController: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate
Would that have caused this to occur?
Yes. That is what caused the issue.
You should either have this:
class MonthViewController: UIViewController, JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {
...
...
...
}
Or this
extension ViewController: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate
Doing that tells the calendar that:
Yes, i conform to your required protocol
If you leave it out, then the calendar does not know that you conform to the protocol and XCode will scream at you.
It is your choice as to where you want to put it. I like putting mine in the extension to keep my code neat. Once you insert that missing line, your error should go away
Let me know if your issue is resolved. And if it is, then you can close this issue 👍
That fixed it!
awesome! Now go build a extremely cool looking calendar and post an image! have a good one.
Hello,
I seem to have an issue on the last real step of the tutorial, which is setting up the dataSource and delegates. I try to set them both to self as is shown in the tutorial and I get an error that "Cannot assign value of type monthViewController(My view handling class name) to JTAppleCalendarDataSource". This is what the troubling section of code looks like.