Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type ViewController does not conform to protocol 'JTAppleCalendarViewDataSource' #58

Closed
yillivs opened this issue Jun 30, 2016 · 13 comments
Assignees
Labels

Comments

@yillivs
Copy link

yillivs commented Jun 30, 2016

I'm sure this isn't too tough of a fix. Around the section where you need to include the protocols to display the calendar I copy paste the extension and both its methods. My code looks like this:

extension CalendarView: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate  {  
    func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate,     numberOfRows: Int, calendar: NSCalendar) {

    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() 
    return (startDate: firstDate!, endDate: secondDate, numberOfRows: numberOfRows, calendar: aCalendar)
}
func calendar(calendar: JTAppleCalendarView, isAboutToDisplayCell cell: JTAppleDayCellView, date: NSDate, cellState: CellState) {
    (cell as! CellView).setupCellBeforeDisplay(cellState, date: date)
}

I get the error that is in the title on the exact line of the extension. Any idea why that could be?

@patchthecode
Copy link
Owner

patchthecode commented Jun 30, 2016

Is the name of your view Controller called -> ViewController ? or is it called CalendarView

In your code, the viewController called CalendarView conforms to the datasource protocol. I do not see where your viewController called ViewController conforming to the protocol. Do you have the code for that?

@patchthecode patchthecode self-assigned this Jun 30, 2016
@patchthecode
Copy link
Owner

Closing issue. It does not seem to be calendar related.

@amrx06
Copy link

amrx06 commented Nov 2, 2016

You copied the code of the tutorial 1: https://patchthecode.github.io/MainTutorial/ I've got the same error when building.

You need to add this method (copied from the iOS example available on GitHub) :

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        let startDate = formatter.date(from: "2016 10 01")!
        let endDate = formatter.date(from: "2016 12 01")!
                let parameters = ConfigurationParameters(startDate: startDate,
                                                 endDate: endDate,
                                                 numberOfRows: numberOfRows,
                                                 calendar: testCalendar,
                                                 generateInDates: generateInDates,
                                                 generateOutDates: generateOutDates,
                                                 firstDayOfWeek: firstDayOfWeek)
        return parameters
}

@patchthecode
Copy link
Owner

@amrx06 i have now fixed the main tutorial. It was missing a , comma symbol. The error is now gone from the tutorial

@rayutsabdeep3
Copy link

rayutsabdeep3 commented Oct 30, 2017

Hello, I found the error, however, I did exactly same like you did in your tutorial. Did you change anything in your library code?
my code,

extension ViewController: JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate{
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {

    formatter.dateFormat = "dd-mm-yyyy"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale

    let startDate = formatter.date(from: "01-01-2000")!
    let endDate = formatter.date(from: "31-12-2030")!

    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
    return cell
}

@patchthecode
Copy link
Owner

@rayutsabdeep3 if you do not explain to me in detail your error, then i cannot help much.

  1. I do not know what your error is.
  2. I do know know what version you upgraded from or what version you are currently using.

@rayutsabdeep3
Copy link

rayutsabdeep3 commented Oct 30, 2017

@patchthecode Apologies.
Type ViewController does not conform to protocol 'JTAppleCalendarViewDelegate' is the error.
and I am using calendar 7.0
XCode 8 and swift 3

@chriseenberg
Copy link

chriseenberg commented Nov 6, 2017

I'm having the same error when following the guide. Type 'ViewController' does not conform to protocol 'JTAppleCalendarViewDelegate' ---> it's missing the method:

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) { <#code#> }

I'm using the version 7.1.1 of Calendar - with swift 4.0

To be honest, i have no idea what to fill into this method, any advice or should i post a stack overflow question with this?

Kind regards Chris

@patchthecode
Copy link
Owner

The 2 major changes in version 7.1.1
were posted on the main page :(
Here is the link to it.

#553

Let me know if this explains it for you.
When ever you get an error like that, XCode suggests the fix for you. Implement the function that XCode is suggesting for you. Click on the red error bubble, and you should see a box that says Fix. Click on fix, and it should put in the missing function for you.

Then fill in that function with the information found here -> #553

@chriseenberg
Copy link

First of all, thank you so much for all the effort you put into this!

Thanks! This solved it for me :)

Kind regards Chris

@patchthecode
Copy link
Owner

Awesome. cheers man 🍻

@onvika
Copy link

onvika commented Jun 26, 2018

Hi, I got this error too.
First, I followed the instructions and I thought it was fixed
this is the code
import UIKit
import JTAppleCalendar

class CalendarioViewController: UIViewController
{

var calendarioView: UICollectionView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

extension CalendarioViewController: JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource
{
func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath)
{
// This function should have the same code as the cellForItemAt function
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "customCell", for: indexPath) as! CalendarCell

    cell.dateLabel.text = cellState.text
}


func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters
{
    let formatter = DateFormatter()
    formatter.dateFormat =  "yyyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale
    
    let startDate = formatter.date(from: "2016 10 01")!
    let endDate = formatter.date(from: "2016 12 01")!
    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! CalendarCell
    
        cell.dateLabel.text = cellState.text
    
    return cell
}

}

Aaand now when I launch the App I'm getting this error
2018-06-26 07:56:55.448430+0200 TFG[14829:6963573] Unknown class JTAppleCalendarView in Interface Builder file.
2018-06-26 07:56:55.467665+0200 TFG[14829:6963573] -[TFG.CalendarioViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb2c9609820
2018-06-26 07:56:55.486283+0200 TFG[14829:6963573] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TFG.CalendarioViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb2c9609820'
*** First throw call stack:
(
0 CoreFoundation 0x00000001079671e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000106ffc031 objc_exception_throw + 48
2 CoreFoundation 0x00000001079e8784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x00000001089636db -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x00000001078e9898 forwarding + 1432
5 CoreFoundation 0x00000001078e9278 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010926ce60 -[UICollectionViewData _updateItemCounts] + 403
7 UIKit 0x000000010926f772 -[UICollectionViewData numberOfSections] + 22
8 UIKit 0x0000000109245467 -[UICollectionViewFlowLayout _getSizingInfosWithExistingSizingDictionary:] + 537
9 UIKit 0x00000001092477db -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 136
10 UIKit 0x0000000109240104 -[UICollectionViewFlowLayout prepareLayout] + 272
11 UIKit 0x000000010926d0a9 -[UICollectionViewData _prepareToLoadData] + 156
12 UIKit 0x000000010926d956 -[UICollectionViewData validateLayoutInRect:] + 53
13 UIKit 0x0000000109203620 -[UICollectionView layoutSubviews] + 260
14 UIKit 0x00000001088047a8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
15 QuartzCore 0x000000010df65456 -[CALayer layoutSublayers] + 177
16 QuartzCore 0x000000010df69667 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
17 QuartzCore 0x000000010def00fb _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
18 QuartzCore 0x000000010df1d79c _ZN2CA11Transaction6commitEv + 568
19 UIKit 0x000000010874f269 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 141
20 CoreFoundation 0x0000000107909b0c CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
21 CoreFoundation 0x00000001078ee2db __CFRunLoopDoBlocks + 331
22 CoreFoundation 0x00000001078eda84 __CFRunLoopRun + 1284
23 CoreFoundation 0x00000001078ed30b CFRunLoopRunSpecific + 635
24 GraphicsServices 0x000000010d803a73 GSEventRunModal + 62
25 UIKit 0x0000000108735057 UIApplicationMain + 159
26 TFG 0x0000000104101887 main + 55
27 libdyld.dylib 0x000000010bd81955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

@patchthecode
Copy link
Owner

patchthecode commented Jun 26, 2018

@onvika
Your very first error says

Unknown class JTAppleCalendarView in Interface Builder file.
This means something is wrong there. Make sure your calendar instance on story board has these 2 values set correctly

screen shot 2018-06-26 at 12 41 11 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants