JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

Crash when creating cell extending JTACMonthCell programatically

Open gotamafandy opened this issue 5 years ago • 4 comments

**(Required) Version Number: 8.0.2

Description

Showing year view crash with assert error: guard let monthView = monthView else { assert(false); return }

Steps To Reproduce

Creating month cell by extending JTACMonthCell programatically.

Expected Behavior

Code should pass assert false

Additional Context

By programatically creating month cell, there's no way to access var monthView: JTACCellMonthView? in parent class.
Making it public and assigning from child will fix the error.

gotamafandy avatar Oct 18 '19 11:10 gotamafandy

Thanks. Year view still has some edgecases to work out. Thanks for letting me know this. Will take a look over the weekend once free. I have some other issues on the issue list looking at, but if this fix is as easy as it sounds, i'll have a look.

patchthecode avatar Oct 18 '19 12:10 patchthecode

@patchthecode any update regarding this issue?

joshuaLareta avatar Dec 11 '19 11:12 joshuaLareta

@joshuaLareta fixed by connecting the monthView outlet from JTACMonthCell to the JTACCellMonthView view in my xib.

nilnilnull avatar Mar 25 '20 20:03 nilnilnull

I ran into this as well. I think the simplest solution if you want to create a JTACMonthCell programatically is to change the accessibility modifier in the class to open, e.g.

open class JTACMonthCell: UICollectionViewCell {
    @IBOutlet open var monthView: JTACCellMonthView?
    weak open var delegate: JTACCellMonthViewDelegate?

This allow a subclass to create the instance of JTACCellMonthView in code (so does not require xib/storyboard) as follows and everything then works, at least in my app.

@patchthecode you open to a PR for this?

 override init(frame: CGRect) {
        super.init(frame: frame)
        monthView = JTACCellMonthView()

robgtsoftware avatar Feb 24 '21 13:02 robgtsoftware