Having issues recreating JTAppleCalender from patch the code

625 views Asked by At

I'm having some issues trying to recreate a calendar from patchthecode's tutorial Here's the link: https://patchthecode.github.io/MainTutorial2/. Here are a few of the error's i'm getting:

1.Cannot assign value of type 'ViewController' to type 'UICollectionViewDataSource?'

2.Cannot assign value of type 'ViewController' to type 'UICollectionViewDelegate?'

3.Value of type 'JTAppleCalendarView?' has no member 'registerCellViewXib'

4.Value of type 'JTAppleCalendarView?' has no member 'cellInset'

5.Use of undeclared type 'DateCell'

6.Invalid redeclaration of 'calendar(_:cellForItemAt:cellState:indexPath:)'

7.Use of unresolved identifier 'myCustomCell'

import UIKit
import JTAppleCalendar
class ViewController: UIViewController {
    let white = UIColor.white
    let darkPurple = UIColor.purple
    let dimPurple = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
@IBOutlet weak var calendarView: JTAppleCalendarView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        super.viewDidLoad()
        calendarView.dataSource = self
        calendarView.delegate = self
        calendarView.registerCellViewXib(file: "CellView") // Registering your cell is manditory
        calendarView.cellInset = CGPoint(x: 0, y: 0)       // default is (3,3)
    }

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

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell: DateCell = JTAppleCell() as! DateCell
        return cell
    }

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

//        let myCustomCell = cell as! CellView

        // Setup Cell text
        myCustomCell.dayLabel.text = cellState.text

        // Setup text color
        if cellState.dateBelongsTo == .thisMonth {
            myCustomCell.dayLabel.textColor = UIColor.black
        } else {
            myCustomCell.dayLabel.textColor = UIColor.gray
        }
    }


func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
    let myCustomCell = calendar.dequeueReusableCell(withReuseIdentifier: "CellView", for: indexPath) as! CellView
//    self.calendar(self.calendar, willDisplay: myCustomCell, forItemAt: date, cellState: cellState, indexPath: indexPath)
    return myCustomCell
    }
    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy MM dd"

        let startDate = formatter.date(from: "2016 02 01")! // You can use date generated from a formatter
        let endDate = Date()                                // You can also use dates created from this function
        let parameters = ConfigurationParameters(startDate: startDate,
                                                 endDate: endDate,
                                                 numberOfRows: 6, // Only 1, 2, 3, & 6 are allowed
            calendar: Calendar.current,
            generateInDates: .forAllMonths,
            generateOutDates: .tillEndOfGrid,
            firstDayOfWeek: .sunday)
        return parameters
    }
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    let myCustomCell = cell as! CellView

    // Let's make the view have rounded corners. Set corner radius to 25
    myCustomCell.selectedView.layer.cornerRadius =  25

    if cellState.isSelected {
        myCustomCell.selectedView.isHidden = false
    }
}
func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
    let myCustomCell = cell as! CellView
    myCustomCell.selectedView.isHidden = true
}
// Function to handle the text color of the calendar
func handleCellTextColor(view: JTAppleCell, cellState: CellState) {

    guard let myCustomCell = view as? CellView  else {
        return
    }

    if cellState.isSelected {
        myCustomCell.dayLabel.textColor = UIColor.purple
    } else {
        if cellState.dateBelongsTo == .thisMonth {
            myCustomCell.dayLabel.textColor = UIColor.white
        } else {
            myCustomCell.dayLabel.textColor = UIColor.purple
        }
    }
}

// Function to handle the calendar selection
func handleCellSelection(view: JTAppleCell?, cellState: CellState) {
    guard let myCustomCell = view as? CellView  else {
        return
    }
    if cellState.isSelected {
        myCustomCell.selectedView.layer.cornerRadius =  25
        myCustomCell.selectedView.isHidden = false
    } else {
        myCustomCell.selectedView.isHidden = true
    }
}
extension UIColor {
    convenience init(colorWithHexValue value: Int, alpha:CGFloat = 1.0){
        self.init(
            red: CGFloat((value & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((value & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(value & 0x0000FF) / 255.0,
            alpha: alpha
        )
    }
}
0

There are 0 answers