Closed benhas999 closed 6 years ago
A bit more information is needed when you say unwanted scrolling
Does it scroll to a date? Does the calendar jump to start? does it fill-in-the-blank?
First of all thanks for such an effort and care you providing to maintain support such a nice library and user interaction, and sorry for missing the necessary details on issue
please check the calendar view...
@benhas999 can you msg me here https://gitter.im/patchthecode/JTAppleCalendar If not respond in 15mins then i'll respond by morning.
ok, you can provide solutions on both portals, hope you got the issue..
This library is a UICollectionView. Therefore use it like you would any other UICollectionView.
i see you have this
if cellState.dateBelongsTo == .thisMonth {
validCell.dateLabel.textColor = monthColor
validCell.jobview.isHidden = false // <---- Why Is This Missing?
} else {
validCell.dateLabel.textColor = outsideMonthColor
validCell.jobview.isHidden = true
}
i am also not sure why you have a loop here
for i in 0 ..< array_calendarData1.count {
// if let perDay = array_calendarData1[i] ?? [CalendarData] {
print(array_calendarData1[i].taskCount)
if array_calendarData1[i].date ?? "" == dateValue {
if array_calendarData1[i].taskCount ?? 0 == 0 {
validCell.jobview.isHidden = true
} else {
validCell.selectedView.backgroundColor = UIColor(white: 1, alpha: 0.7)
validCell.jobview.isHidden = false
validCell.joblabel.text = "\(array_calendarData1[i].taskCount ?? 0)"
}
break
}
It looks like you are looping through your dataSource to set the variables of many cells in on shot. If you are using it the way i think you're using it, then this is not the way you setup data in a cell for a UIcollectionView.UITableView. You need to get the data of one cell, and set it up. Because that function is called many times to setup every visible cell on the screen.
if array_calendarData1[i].date ?? "" == dateValue
Its how i manage to check the job is available For current date, from bulk given data how can i check whether the data avilable for a cell without loop..??
if cellState.dateBelongsTo == .thisMonth { validCell.dateLabel.textColor = monthColor validCell.jobview.isHidden = false // <---- Why Is This Missing? } Its setting inside the data checking loop.. Is that enough...??
Is it you think the reason for scroll/data missing..
@benhas999 available here? https://gitter.im/patchthecode/JTAppleCalendar
please find the calendar class
import Foundation
import UIKit
import JTAppleCalendar
import Firebase
import Alamofire
// Class Description - Calendar View: Calendar view Listed with Leave days, jobs per day listed
class CalendarViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet var lbl_tuesday: UILabel!
@IBOutlet var lbl_monday: UILabel!
@IBOutlet var lbl_wednesday: UILabel!
@IBOutlet var lbl_thursday: UILabel!
@IBOutlet var lbl_friday: UILabel!
@IBOutlet var lbl_saturday: UILabel!
@IBOutlet var lbl_sunday: UILabel!
@IBOutlet var topBar: UIView!
@IBOutlet weak var calendarView: JTAppleCalendarView!
var initialLoad = true
@IBOutlet var lbl_title: UILabel!
@IBOutlet weak var lbl_month: UILabel!
@IBOutlet var view_jobsOnDatesColor: UIView!
@IBOutlet var view_leaveDatesColor: UIView!
@IBOutlet var lbl_jobsOnDates: UILabel!
@IBOutlet var lbl_myLeaveDays: UILabel!
@IBOutlet var btn_left: UIButton!
@IBOutlet var btn_right: UIButton!
var selecteddate: Date? = nil
var testCalendar = Calendar.current
let outsideMonthColor = UIColor(colorWithHexValue: 0xECEAED)
let monthColor = UIColor(colorWithHexValue: 0x3A284C)
//let dimPurple = UIColor(colorWithHexValue: 0x574865)
let formatter = DateFormatter()
fileprivate lazy var selectedDateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
return formatter
}()
var clickPosition: CGPoint?
var startDateVar = Date()
var endDateVar = Calendar.current.date(byAdding: .month, value: 1, to: Date())
let table_dayOptions = UITableView()
var serviceHandler = WebServiceHandler()
var colorObject = ColorFile()
var fontObject = FontFile()
var array_options = [localisationString("add_leave"), localisationString("edit_leave"), localisationString("jobs")]
//var array_calendarData = [CalendarData]()
//var array_leaveDays = [LeaveDays]()
var array_calendarData1 = [CalendarData]()
var array_leaveDays1 = [LeaveDays]()
override var textInputMode: UITextInputMode? {
do {
for inputMode: UITextInputMode in UITextInputMode.activeInputModes {
print(inputMode.primaryLanguage)
if (inputMode.primaryLanguage == setKeyBoardCode(languageCode: ((UserDefaults.standard.value(forKey: "language") ?? "en") as? String)!)) {
return inputMode
}
}
return super.textInputMode
}
}
override func viewDidLoad() {
// let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
// tap.delegate = self
// calendarView.addGestureRecognizer(tap)
//disable swipe back gesture
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
table_dayOptions.delegate = self
table_dayOptions.dataSource = self
//self.initialSettings()
self.tabBarController?.tabBar.isHidden = false
self.tabBarItem.selectedImage = self.tabBarItem.image?.withRenderingMode(.alwaysOriginal)
self.initialSettings()
}
func handleTap(sender: UITapGestureRecognizer? = nil) {
// handling code
// clickPosition = sender.
}
override func viewWillAppear(_ animated: Bool) {
if let tb = self.view.viewWithTag(500)
{
tb.removeFromSuperview()
}
initialLoad = true
removeToast(onView: self.view)
setupCalendarView()
}
override func viewDidAppear(_ animated: Bool) {
FIRAnalytics.setScreenName("CalendarViewController", screenClass: "CalendarViewController")
self.tabBarController?.tabBar.isHidden = false
self.tabBarItem.selectedImage = self.tabBarItem.image?.withRenderingMode(.alwaysOriginal)
if self.serviceHandler.isReachable() == false {
createToastWithMessage(onView: self.view, message: localisationString("network_connection_fail"), positionY: self.view.frame.size.height / 2 - 50)
}
else {
self.monthlyJobListServiceCall(startDateVar: startDateVar, endDateVar: endDateVar!)
}
}
//MARK: - Initial settings
/*!
* Method : initialSettings
* @discussion
* @param
* @param
* @return
*/
func initialSettings()
{
//setting alignment
self.calendarView.semanticContentAttribute = .forceLeftToRight
//setting text
self.lbl_title.text = localisationString("calendar").uppercased()
self.lbl_month.text = localisationString("month_year").uppercased()
self.lbl_jobsOnDates.text = localisationString("jobsOnDates").uppercased()
self.lbl_myLeaveDays.text = localisationString("myLeaveDays").uppercased()
//setting color
self.topBar.backgroundColor = self.colorObject.setTopBarBGcolor()
self.btn_left.backgroundColor = UIColor.init(colorWithHexValue: 0xadadad)
self.btn_right.backgroundColor = UIColor.init(colorWithHexValue: 0xadadad)
//setting colors
self.topBar.backgroundColor = self.colorObject.setTopBarBGcolor()
self.lbl_title.textColor = UIColor.white
self.lbl_month.textColor = self.colorObject.setGrayColor()
self.lbl_jobsOnDates.textColor = self.colorObject.setGrayColor()
self.lbl_myLeaveDays.textColor = self.colorObject.setGrayColor()
self.calendarView.backgroundColor = UIColor.white
//setting fonts
self.lbl_title.font = self.fontObject.setBoldFont(15)
self.lbl_month.font = self.fontObject.setBoldFont(15)
self.lbl_jobsOnDates.font = self.fontObject.setBoldFont(8)
self.lbl_myLeaveDays.font = self.fontObject.setBoldFont(8)
if UI_USER_INTERFACE_IDIOM() == .pad {
self.lbl_title.font = self.fontObject.setBoldFont(19)
self.lbl_month.font = self.fontObject.setBoldFont(19)
self.lbl_jobsOnDates.font = self.fontObject.setBoldFont(10)
self.lbl_myLeaveDays.font = self.fontObject.setBoldFont(10)
}
}
//MARK: - View touch action
/*!
* Method : touchesBegan
* @discussion
* @param
* @param
* @return
*/
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
clickPosition = touch.location(in: self.calendarView)
}
}
//MARK: - Service call - Monthly job listing
/*!
* Method : monthlyJobListServiceCall
* @discussion
* @param startDateVar : holds starting date
* @param endDateVar : holds ending date
* @return
*/
func monthlyJobListServiceCall(startDateVar: Date, endDateVar: Date) {
ProgressBar.show()
(startDateVar)
(endDateVar)
let userId = UserDefaults.standard.value(forKey: "UserId") as? Int ?? 0
let language = UserDefaults.standard.value(forKey: "language") as? String ?? ""
var formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
let startDate = formatter.string(from: startDateVar)
let endDate = formatter.string(from: endDateVar)
let urlString = "\(ApiService.TaskCalendar)/\(userId)/\(startDate)/\(endDate)/\(language)"
(urlString)
Alamofire.request(urlString, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { response in
(response)
switch response.result {
case .success:
ProgressBar.hide()
if let json = response.result.value {
let resultData = json as! NSDictionary
if Validate.jsonResponseValidation(resultObject: resultData) == false {
createToastWithMessage(onView: self.view, message: localisationString("network_issues"), positionY: UIScreen.main.bounds.size.height / 2)
return
}
let messageType = resultData.value(forKey: "MessageTypeString") as! String
if messageType == "Success" {
if let results = resultData.value(forKey: "Result") {
let obj_calndarJobs = CalendarModel(object:resultData)
let dictResult = obj_calndarJobs.result
// self.array_calendarData = NSArray()
// self.array_leaveDays = NSArray()
self.array_calendarData1 = dictResult?.calendar ?? []
self.array_leaveDays1 = dictResult?.leaveDays ?? []
DispatchQueue.main.async {
self.calendarView.calendarDelegate = self
self.calendarView.calendarDataSource = self
let selectedDates = self.calendarView.selectedDates
//self.calendarView.deselectAllDates(triggerSelectionDelegate: false)
//Other things
self.calendarView.reloadDates(selectedDates)
self.calendarView.reloadData()
if(self.initialLoad)
{
self.calendarView.scrollToDate(startDateVar)
self.initialLoad = false
}
}
} else {
DispatchQueue.main.async {
// createToastWithMessage(onView: self.view.window!, message: "Wallet history not available", positionY: self.view.frame.size.height / 2)
}
}
} else {
DispatchQueue.main.async {
// createToastWithMessage(onView: self.view.window!, message: "Wallet history not available", positionY: self.view.frame.size.height / 2)
}
}
} else {
DispatchQueue.main.async {
// createToastWithMessage(onView: self.view.window!, message: "Wallet history not available", positionY: self.view.frame.size.height / 2)
}
}
case .failure(_):
ProgressBar.hide()
if let json = response.result.value {
let resultData = json as! NSDictionary
if resultData.value(forKey: "ErrorMessage") == nil {
createToastWithMessage(onView: self.view, message: localisationString("network_issues"), positionY: UIScreen.main.bounds.size.height / 2)
} else {
createToastWithMessage(onView: self.view, message: resultData.value(forKey: "ErrorMessage") as? String ?? localisationString("network_issues"), positionY: UIScreen.main.bounds.size.height / 2)
}
}
}
}
}
// func monthlyJobListServiceCall(startDateVar:Date,endDateVar:Date) {
// let activityData = ActivityData()
// NVActivityIndicatorPresenter.sharedInstance.startAnimating(activityData)
//
// (startDateVar)
// (endDateVar)
//
// let userId = UserDefaults.standard.value(forKey: "UserId")!
// let language = UserDefaults.standard.value(forKey: "language")!
//
//// let userId = 1
//// let language = "en"
//
// let formatter = DateFormatter()
// formatter.dateFormat = "yyyy-MM-dd"
//
// let startDate = formatter.string(from: startDateVar)
// let endDate = formatter.string(from: endDateVar)
//
//// (startDate)
//// (endDate)
// //let urlString="\(kBaseTaskURL!)\(calendarJobURL!)/\(userId)/\(startDate!)/\(endDate!)/\(language)"
//
// let urlString="\(kBaseTaskURL!)\(calendarJobURL!)/\(userId)/\(startDate)/\(endDate)/\(language)"
//// (urlString)
//
//
// self.serviceHandler.serviecCallGet(urlString, callback: { (response) in
// if let responseDictionary = response as? NSDictionary {
//
// (responseDictionary)
//
//// (responseDictionary)
//
// let status : NSString = responseDictionary.value(forKey: "MessageTypeString") as! NSString
// DispatchQueue.main.async {
// NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
// }
//
// if status == "Success" {
// let dictResult = responseDictionary.value(forKey: "Result") as! NSDictionary
//
//
// //remove existing values
//
// self.array_calendarData = NSArray()
// self.array_leaveDays = NSArray()
//
//
// self.array_calendarData = dictResult.value(forKey: "Calendar") as! NSArray
// self.array_leaveDays = dictResult.value(forKey: "LeaveDays") as! NSArray
//
// DispatchQueue.main.async {
//
// self.calendarView.calendarDelegate = self
// self.calendarView.calendarDataSource = self
//
// let selectedDates = self.calendarView.selectedDates
// //self.calendarView.deselectAllDates(triggerSelectionDelegate: false)
// //Other things
// self.calendarView.reloadDates(selectedDates)
// self.calendarView.reloadData()
// if(self.initialLoad)
// {
// self.calendarView.scrollToDate(startDateVar)
// self.initialLoad = false
// }
//
// }
//
//
// }
//
// else {
//// createToastWithMessage(onView: self.view, message: localisationString("user_exists"), positionY: self.view.frame.size.height/2 - 50)
// }
//
// }
//
// })
//
// }
//MARK: - SetUp Calender View
/*!
* Method : setupCalendarView
* @discussion
* @param
* @param
* @return
*/
func setupCalendarView()
{
//setup labels
calendarView.visibleDates { (visibleDates) in
let date = visibleDates.monthDates.first!.date
self.formatter.dateFormat = "MMM - yyyy"
//self.lbl_month.text = self.formatter.string(from: date)
}
self.view_jobsOnDatesColor.backgroundColor = self.colorObject.setGreenColorCode()
self.view_leaveDatesColor.backgroundColor = self.colorObject.setRedColor()
}
//MARK: - Cell text colour
/*!
* Method : handleCelltextColor
* @discussion
* @param view holder view object
* @param cellState state of a cell
* @return
*/
func handleCelltextColor(view: JTAppleCell?, cellState: CellState) {
guard let validCell = view as? CustomCalendarCell else {
return }
let dateValue = self.formatter.string(from: cellState.date)
validCell.jobview.backgroundColor = self.colorObject.setGreenColorCode()
if cellState.dateBelongsTo == .thisMonth {
validCell.dateLabel.textColor = monthColor
} else {
validCell.dateLabel.textColor = outsideMonthColor
validCell.jobview.isHidden = true
}
for i in 0 ..< array_calendarData1.count {
// if let perDay = array_calendarData1[i] ?? [CalendarData] {
if array_calendarData1[i].date ?? "" == dateValue {
if array_calendarData1[i].taskCount ?? 0 == 0 {
validCell.jobview.isHidden = true
} else {
validCell.selectedView.backgroundColor = UIColor(white: 1, alpha: 0.7)
validCell.jobview.isHidden = false
validCell.joblabel.text = "\(array_calendarData1[i].taskCount ?? 0)"
}
break
}
//}
// else {
// validCell.selectedView.backgroundColor = UIColor(white: 1, alpha: 1)
// validCell.selectedView.layer.borderWidth = 0
// validCell.jobview.isHidden = true
// validCell.joblabel.text = ""
//
// }
//
if testCalendar.isDateInToday(cellState.date) {
// validCell.dateLabel.textColor = UIColor.red
}
}
for i in 0..<self.array_leaveDays1.count {
let perDay = array_leaveDays1[i]
if(perDay.startDate ?? "").contains(dateValue)
{
validCell.dateLabel.textColor = self.colorObject.setRedColor()
}
else {
}
}
}
// optional changes for cell
func handleCellSelected(view: JTAppleCell?, cellState: CellState) {
guard let validCell = view as? CustomCalendarCell else { return }
}
// MARK: - handle Long Press
/**
@Des: Whenever user longclick on calenderview cell
- parameters:
- sender : long press recognizer
*/
func handleLongPress(sender: UILongPressGestureRecognizer) {
if sender.state != UIGestureRecognizerState.ended {
return
}
// let longPressedPoint = sender.location(in: calendarView)
// var indexPathOfLongPressedCell = self.calendarView.indexPathForItem(at: longPressedPoint)
//// (indexPathOfLongPressedCell)
//
//
// var currentCell = calendarView.cellForItem(at: indexPathOfLongPressedCell!) as! CustomCalendarCell
//
// if currentCell == nil {
// return
//
// }
//
//// (currentCell.date)
//// (currentCell.date.addingTimeInterval(86400))
// // ing value needs to add one day but on passing to label its correct!!
// let currentDate = currentCell.date.addingTimeInterval(86400)
//
//// ("currentdate:\(currentDate)")
//
// handleAlert(currentCell: currentCell, currentDate: currentDate,longPressedPoint:longPressedPoint)
}
/*!
* Method : handleAlert
* @discussion
* @param currentCell object holding reference to current cell
* @param currentDate
* @param longPressedPoint bject holding reference to point in which user holds long press
* @return
*/
func handleAlert(currentCell: CustomCalendarCell, currentDate: Date, longPressedPoint: CGPoint)
{
table_dayOptions.tag = 500
//table_dayOptions.rowHeight = 20
table_dayOptions.isScrollEnabled = false
table_dayOptions.separatorStyle = .none
self.selecteddate = currentDate
//check whether selected date has tasks
//let dateValue = self.formatter.string(from: currentDate)
DispatchQueue.main.async
{
if let tb = self.view.viewWithTag(500)
{
tb.removeFromSuperview()
}
}
let today = Date()
if currentDate < today || currentCell.dateLabel.textColor == self.colorObject.setRedColor()
{
//createToastWithMessage(self.view)
return
}
//check whether selected date is leave
if currentCell.dateLabel.textColor == self.colorObject.setRedColor() {
//self.array_options = [localisationString("edit_leave")]
}
else if currentCell.jobview.isHidden == false {
self.array_options = [localisationString("jobs")]
}
else {
self.array_options = [localisationString("add_leave")]
}
DispatchQueue.main.async {
self.table_dayOptions.frame = CGRect(x: longPressedPoint.x, y: longPressedPoint.y + 65, width: self.view.frame.width / 4, height: self.table_dayOptions.contentSize.height)
if UI_USER_INTERFACE_IDIOM() == .pad {
self.table_dayOptions.frame = CGRect(x: longPressedPoint.x, y: longPressedPoint.y + 80, width: self.view.frame.width / 4, height: self.table_dayOptions.contentSize.height)
(longPressedPoint.x)
}
if self.table_dayOptions.frame.origin.x + self.table_dayOptions.frame.width > self.view.frame.width
{
(self.view.frame.width)
(self.table_dayOptions.frame.origin.x + self.table_dayOptions.frame.width)
self.table_dayOptions.frame = CGRect(x: self.view.frame.width - (self.calendarView.frame.width / 4) - 10, y: longPressedPoint.y + 65, width: self.calendarView.frame.width / 4, height: self.table_dayOptions.contentSize.height)
}
self.view.addSubview(self.table_dayOptions)
self.table_dayOptions.reloadData()
}
}
@IBAction func leftBtnClicked(_ sender: Any) {
}
@IBAction func rightBtnClicked(_ sender: Any) {
}
}
extension CalendarViewController: UITableViewDelegate, UITableViewDataSource
{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array_options.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if UI_USER_INTERFACE_IDIOM() == .pad {
return 40
}
return 20
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let btn = UIButton(type: .custom)
btn.backgroundColor = colorObject.setTopBarBGcolor()
btn.setTitle(array_options[indexPath.row].uppercased(), for: .normal)
btn.setTitleColor(UIColor.white, for: .normal)
btn.titleLabel?.font = fontObject.setBoldFont(12)
btn.titleLabel?.textAlignment = .center
btn.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: 20)
btn.tag = indexPath.row
btn.addTarget(self, action:
#selector(optionSelected(sender:)), for: .touchUpInside)
let divideView = UIView(frame: CGRect(x: 0, y: 18, width: tableView.frame.width, height: 2))
if UI_USER_INTERFACE_IDIOM() == .pad {
btn.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: 40)
divideView.frame = CGRect(x: 0, y: 38, width: tableView.frame.width, height: 2)
btn.titleLabel?.font = fontObject.setBoldFont(15)
}
divideView.backgroundColor = UIColor.white
cell.addSubview(btn)
cell.addSubview(divideView)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// (indexPath.row)
}
func optionSelected(sender: UIButton)
{
switch(sender.titleLabel?.text)
{
case localisationString("add_leave")?:
let createLeaveView = self.storyboard?.instantiateViewController(withIdentifier: "CreateLeaveViewController") as! CreateLeaveViewController
createLeaveView.displayDate = self.selecteddate!
// (selecteddate!)
self.navigationController?.pushViewController(createLeaveView, animated: true)
case localisationString("edit_leave")?:
break
case localisationString("jobs")?:
let joblistView = self.storyboard?.instantiateViewController(withIdentifier: "CalendarJobDetailListViewController") as! CalendarJobDetailListViewController
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")!
let sel_date = dateFormatter.string(from: self.selecteddate!)
// (sel_date)
joblistView.selectedDate = sel_date
self.navigationController?.pushViewController(joblistView, animated: true)
default:
break
}
}
}
extension CalendarViewController: JTAppleCalendarViewDataSource {
//Configure basic calender parameters such as strat month,end
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters
{
// let formatter = DateFormatter()
// formatter.dateFormat = "dd-MM-yyyy"
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
// let startDate = formatter.date(from:"2017 05 01")
// let endDate = formatter.date(from: "2017 12 31")
let startDate = Date()
let endDate = Calendar.current.date(byAdding: .year, value: 1, to: startDate)
let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate!, firstDayOfWeek: DaysOfWeek(rawValue: 2))
return parameters
}
}
extension CalendarViewController: JTAppleCalendarViewDelegate
{
//basic cell implementation
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCalendarCell", for: indexPath) as! CustomCalendarCell
// (cellState.text)
cell.dateLabel.text = cellState.text
cell.date = date
//Long press on cell
// let lpgr = UILongPressGestureRecognizer(target: self, action:#selector(handleLongPress(sender:)))
// lpgr.minimumPressDuration = 0.5
// lpgr.delaysTouchesBegan = true
// lpgr.delegate = self
// cell.addGestureRecognizer(lpgr)
//cell.layer.borderWidth = 0.1
cell.layer.borderColor = UIColor.black.cgColor
handleCelltextColor(view: cell, cellState: cellState)
return cell
}
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
guard let validCell = cell as? CustomCalendarCell else {
return
}
(date)
let currentDate = date.addingTimeInterval(86400)
let realCenter = calendar.convert(validCell.center, to: calendar.superview)
// ("currentdate:\(currentDate)")
handleAlert(currentCell: validCell, currentDate: currentDate, longPressedPoint: realCenter)
}
func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
let date1 = visibleDates.monthDates.first!.date
let date2 = visibleDates.monthDates.last!.date
// (date1)
// (date2)
formatter.dateFormat = "MMMM - yyyy"
if lbl_month.text != formatter.string(from: date1)
{
lbl_month.text = formatter.string(from: date1)
if let tb = self.view.viewWithTag(500)
{
tb.removeFromSuperview()
}
}
startDateVar = date1
endDateVar = date2
if self.initialLoad
{
self.initialLoad = false
return
}
monthlyJobListServiceCall(startDateVar: startDateVar, endDateVar: endDateVar!)
}
}
Ok just a note. Im here to help you with any issues related to the libray, and not issues related to your application (because this will be too much for me to look through). I did ask to see code, but not code without context. After we spoke via chat, what was the outcome of the implementation? And cannot tell anything if i do not know the context of this pasted code. So can you help me out a lil? :)
you just mistaken, i specified library related codes in seprate extension.. you just have to concern it, ofcourse myself also not interested to deal with others code for time pass... :)
from our conversation as you asked about handling arrays, incase you have any doubts about global datastructures or assigning methods you can just find the roots, thats it..
Please just find the refined code
extension CalendarViewController: JTAppleCalendarViewDataSource {
//Configure basic calender parameters such as strat month,end
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters
{
// let formatter = DateFormatter()
// formatter.dateFormat = "dd-MM-yyyy"
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
// let startDate = formatter.date(from:"2017 05 01")
// let endDate = formatter.date(from: "2017 12 31")
let startDate = Date()
let endDate = Calendar.current.date(byAdding: .year, value: 1, to: startDate)
let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate!, firstDayOfWeek: DaysOfWeek(rawValue: 2))
return parameters
}
}
extension CalendarViewController: JTAppleCalendarViewDelegate
{
//basic cell implementation
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCalendarCell", for: indexPath) as! CustomCalendarCell
// (cellState.text)
cell.dateLabel.text = cellState.text
cell.date = date
//Long press on cell
// let lpgr = UILongPressGestureRecognizer(target: self, action:#selector(handleLongPress(sender:)))
// lpgr.minimumPressDuration = 0.5
// lpgr.delaysTouchesBegan = true
// lpgr.delegate = self
// cell.addGestureRecognizer(lpgr)
//cell.layer.borderWidth = 0.1
cell.layer.borderColor = UIColor.black.cgColor
handleCelltextColor(view: cell, cellState: cellState)
return cell
}
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
guard let validCell = cell as? CustomCalendarCell else {
return
}
(date)
let currentDate = date.addingTimeInterval(86400)
let realCenter = calendar.convert(validCell.center, to: calendar.superview)
// ("currentdate:\(currentDate)")
handleAlert(currentCell: validCell, currentDate: currentDate, longPressedPoint: realCenter)
}
func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
let date1 = visibleDates.monthDates.first!.date
let date2 = visibleDates.monthDates.last!.date
// (date1)
// (date2)
formatter.dateFormat = "MMMM - yyyy"
if lbl_month.text != formatter.string(from: date1)
{
lbl_month.text = formatter.string(from: date1)
if let tb = self.view.viewWithTag(500)
{
tb.removeFromSuperview()
}
}
startDateVar = date1
endDateVar = date2
if self.initialLoad
{
self.initialLoad = false
return
}
monthlyJobListServiceCall(startDateVar: startDateVar, endDateVar: endDateVar!)
}
}
//MARK: - Cell text colour
/*!
* Method : handleCelltextColor
* @discussion
* @param view holder view object
* @param cellState state of a cell
* @return
*/
func handleCelltextColor(view: JTAppleCell?, cellState: CellState) {
guard let validCell = view as? CustomCalendarCell else {
return }
let dateValue = self.formatter.string(from: cellState.date)
validCell.jobview.backgroundColor = self.colorObject.setGreenColorCode()
if cellState.dateBelongsTo == .thisMonth {
validCell.dateLabel.textColor = monthColor
} else {
validCell.dateLabel.textColor = outsideMonthColor
validCell.jobview.isHidden = true
}
for i in 0 ..< array_calendarData1.count {
// if let perDay = array_calendarData1[i] ?? [CalendarData] {
if array_calendarData1[i].date ?? "" == dateValue {
if array_calendarData1[i].taskCount ?? 0 == 0 {
validCell.jobview.isHidden = true
} else {
validCell.selectedView.backgroundColor = UIColor(white: 1, alpha: 0.7)
validCell.jobview.isHidden = false
validCell.joblabel.text = "\(array_calendarData1[i].taskCount ?? 0)"
}
break
}
//}
// else {
// validCell.selectedView.backgroundColor = UIColor(white: 1, alpha: 1)
// validCell.selectedView.layer.borderWidth = 0
// validCell.jobview.isHidden = true
// validCell.joblabel.text = ""
//
// }
//
if testCalendar.isDateInToday(cellState.date) {
// validCell.dateLabel.textColor = UIColor.red
}
}
for i in 0..<self.array_leaveDays1.count {
let perDay = array_leaveDays1[i]
if(perDay.startDate ?? "").contains(dateValue)
{
validCell.dateLabel.textColor = self.colorObject.setRedColor()
}
else {
}
}
}
sorry about the misunderstanding.. i think handling month in cells interms of indexpath can solve the problem, may all the cell consist of tasks thus assigning according to indexpath by differantiating indates is only solution, any suggestion...
Using Latest version of JTApple calendar
but it shows as it for few scrolls then the indication shows on wrong dates
i just created xib file and implemented following views but they get nil, while try to deque and change color.
is it the correct method to register the view with JTApple calendar @ @patchthecode