I added JTAppleCalendar
inside my project and I want to add some tags in some of my calendar cells. I have success adding them, but when I scroll left or right on my calendar months, cells inside tags disappear, hide, or mix, and when I scroll again and again there is more and more mixing. Do I need any protocols or delegates, etc.? Or, it is just a bug?
How can I fix that bug?
My cellForItemAt
code:
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableCell(withReuseIdentifier: "CellView", for: indexPath) as! CellView
var currentdate = String(describing: myCalendar.date(byAdding: .day, value: 1, to: cellState.date))
currentdate = currentdate.substring(from: 9, length: 10)
cell.tagList.tags.removeAll()
cell.tagList.hide()
cell.contentView.backgroundColor = nil
cell.tagList.alpha = 0
cell.tagList.numberOfRows = 0
cell.tagList.backgroundColor = UIColor.clear
cell.tagList.isHidden = true
var i : Int
i = 0
for object in datas {
i = i + 1
let clean = "\(object)".components(separatedBy: "*")
if clean[0] == currentdate {
let gotag : Int
gotag = Int(clean[1])!
cell.tagList.isHidden = false
cell.dayLabel.text = cellState.text
cell.contentView.backgroundColor = UIColor.gray
let itemName = "Item name \(i)"
cell.tagList.alpha = 1
if clean[1] == "1" {
cell.tagList.addTag(itemName, target: self, tapAction: #selector(ViewController.tap(_:)), longPressAction: #selector(ViewController.tap(_:)),backgroundColor: UIColor.orange,textColor: UIColor.white,comesTag: gotag)
}else if clean[1] == "2" {
cell.tagList.addTag(itemName, target: self, tapAction: #selector(ViewController.tap(_:)), longPressAction: #selector(ViewController.tap(_:)),backgroundColor: UIColor.green,textColor: UIColor.white,comesTag: gotag)
}else if clean[1] == "3" {
cell.tagList.addTag(itemName, target: self, tapAction: #selector(ViewController.tap(_:)), longPressAction: #selector(ViewController.tap(_:)),backgroundColor: UIColor.brown,textColor: UIColor.white,comesTag: gotag)
}else if clean[1] == "4" {
cell.tagList.addTag(itemName, target: self, tapAction: #selector(ViewController.tap(_:)), longPressAction: #selector(ViewController.tap(_:)),backgroundColor: UIColor.black,textColor: UIColor.white,comesTag: gotag)
}
}else{
cell.tagList.backgroundColor = UIColor.clear
}
}
handleCellConfiguration(cell: cell, cellState: cellState)
return cell
}
Bug in action:
https://github.com/LetSwiftDev/CalendarBug/blob/master/calendarbug.gif
Also you can join official JTAppleCalendar chat here https://gitter.im/patchthecode/JTAppleCalendar