Jtapplecalendar: Crash occurs when making JTCanlendarView as a new XIB

Created on 2 Aug 2017  路  14Comments  路  Source: patchthecode/JTAppleCalendar

version: 7.0.6

Hi. When I watch the guide video, the CalendarView is created inside of storyBoard, under the viewController. For the reusability, I created a new XIB file and class file, declared as CalendarView and tried to load this xib from different class, using below code snippet, it occurs crash.

// Codes in other view controller let aCalendarView = Bundle.main.loadNibNamed("CalendarView", owner: self, options: nil)?.first as? CalendarView // << crash here self.view.addSubView(aCalendarView)

Crash is occurred in JTAppleCalendarView's init function,
/// Initializes using decoder object required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupNewLayout(from: collectionViewLayout as! JTAppleCalendarLayoutProtocol) // << crash here. Log is "EXC_BAD_ACCESS". }

Is there any way to make JTAppleCalendar as separated XIB?

Most helpful comment

Found the issue! As I suspected, very small and silly indeed :P
There's one wrong line in the tutorial (or maybe it's just not updated for version 7).
Was making the JTAppleCalendarView out of a UIView as mentioned in the tut. Needed to make it out of a UICollectionView instead! Hence the crash at setting up layout.
Thanks though for the quick response @patchthecode !
Appreciate the help thoroughly.

All 14 comments

I miss understood the usage. forget about it :)

cool. glad its sorted out.

Facing the exact same issue in the exact same situation. @ahimahas, could you please explain what was the misunderstanding?

@electroqted what crash are you experiencing? error message?

And can you let us know what code you have for the initialization?

I have a view controller CalendarViewController in which i have the JTAppleCalendarView
Code for the viewcontroller is this :

public class CalendarViewController: UIViewController, JTAppleCalendarViewDataSource, JTAppleCalendarViewDelegate {

 @IBOutlet weak var MyCalendarView: JTAppleCalendarView!

  override public func viewDidLoad() {
        MyCalendarView.calendarDataSource = self
        MyCalendarView.calendarDelegate = self
        MyCalendarView.register(UINib(nibName: "CalendarCell", bundle: NewActionUITableDataSource.bundle), forCellWithReuseIdentifier: "CalendarCell")
}

It crashes right in the initialization of the viewcontroller class itself, at the '@IBOutlet weak var MyCalendarView: JTAppleCalendarView!' line.
Crashing function is
setupNewLayout(from: collectionViewLayout as! JTAppleCalendarLayoutProtocol) // << "EXC_BAD_ACCESS".

I've also attached a screenshot of the storyboard with the viewcontroller.
Nothing much, only the jtcalendarview

screen shot 2017-09-08 at 8 56 03 pm

I'm sure it's a very small silly mistake, just can't seem to nail it down though.

@electroqted since your project is small. Can you zip it and drag it into this chat box? I'll take a look.

Found the issue! As I suspected, very small and silly indeed :P
There's one wrong line in the tutorial (or maybe it's just not updated for version 7).
Was making the JTAppleCalendarView out of a UIView as mentioned in the tut. Needed to make it out of a UICollectionView instead! Hence the crash at setting up layout.
Thanks though for the quick response @patchthecode !
Appreciate the help thoroughly.

@electroqted oh. You were reading the tutorials? I thought you were looking at the video tutorial list located --> Here. It explains many things. Just look at the videos that you need to see, and skip the others.

@electroqted @patchthecode I have the very same issue. I'm trying to create my calendar in a .xib instead of storyboard. I also followed the tutorials, and adapted to v7 when needed, but it crashed just like yours did.

Could you please tell me which is the wrong line in the tutorial or instructions on how to fix it? I also opened an issue https://github.com/patchthecode/JTAppleCalendar/issues/642

Thank you very much.

videos are private , so cant view

@david-opendna private because they would cause more trouble than help.
Library gets updated, but videos cannot.

I instead created tutorials. Have you checked them out? www.patchthecode.com

i get Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) on line below when calling setupNewLayout, just recently upgraded to version 7, im using Xcode11 and iOS13

required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupNewLayout(from: collectionViewLayout as! JTAppleCalendarLayoutProtocol)
    }

from call stack this line is called before the crash.

  `  let cell = tableView.dequeueReusableCell(withIdentifier: MypageCalendarTableViewCell.Identifier) as! MypageCalendarTableViewCell

`

what does the log say. Can you paste me the log?

there is no log , nothing is printed to console

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dimitris-c picture dimitris-c  路  5Comments

blinkmeoff picture blinkmeoff  路  3Comments

oddpandadesign picture oddpandadesign  路  5Comments

arn00s picture arn00s  路  3Comments

Fatalution picture Fatalution  路  3Comments