Open fuzunspm opened 7 years ago
I found a solution to this issue here:
Now it’s crashes on app delegate I’m on mobile I will paste the error
whenever i try to choose dates it crashes with the error below. No output to the console
Thread 1: EXC_BAD_ACCESS (code=1, address=0x2000186c)
I found the solution.
Step 1. Add this line in EPCalendarPicker.swift, Method : public init(startYear: Int, endYear: Int, multiSelection: Bool, selectedDates: [Date]?)
Lines To Add : let rect = UIScreen.main.bounds let screenWidth = rect.size.width - 7 layout.itemSize = CGSize(width: screenWidth/7, height: screenWidth/7)
Step 2 : Remove This Method : func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
let rect = UIScreen.main.bounds
let screenWidth = rect.size.width - 7
return CGSize(width: screenWidth/7, height: screenWidth/7);
}
Add @objc in method to look like :
@objc func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets
{
return UIEdgeInsetsMake(5, 0, 5, 0); //top,left,bottom,right
}
Everything is working now.
To Show the Calendar call below method :
func showCalender() {
let calendarPicker = EPCalendarPicker(startYear: 2017, endYear: 2099, multiSelection: false, selectedDates: [])
calendarPicker.calendarDelegate = self
calendarPicker.startDate = Date()
calendarPicker.hightlightsToday = true
calendarPicker.hideDaysFromOtherMonth = true
calendarPicker.tintColor = UIColor.defaultAppColorDarkBlue
// calendarPicker.barTintColor = UIColor.greenColor()
calendarPicker.dayDisabledTintColor = UIColor.lightGray
calendarPicker.monthTitleColor = UIColor.black
calendarPicker.todayTintColor = UIColor.clear
// calendarPicker.showsTodaysButton = false
calendarPicker.weekendTintColor = UIColor.lightGray
calendarPicker.weekdayTintColor = UIColor.darkGray
calendarPicker.title = "DATE SELECT"
calendarPicker.tintColor = UIColor.black
calendarPicker.dateSelectionColor = UIColor.defaultAppColorDarkBlue
let navigationController = UINavigationController(rootViewController: calendarPicker)
// self.present(navigationController, animated: true, completion: nil)
self.present(navigationController, animated: true) {
navigationController.updateFocusIfNeeded()
self.view.setNeedsLayout()
}
}
Currently it's not working on Swift 4.0. It builds but whenever i try to choose date it crashes with the error below:
*** /Users/x/Desktop/x/x/x/EPCalendarPicker/EPCalendarPicker.swift:254:5: implicit Objective-C entrypoint -[x.EPCalendarPicker collectionView:layout:sizeForItemAtIndexPath:] is deprecated and will be removed in Swift 4; add explicit '@objc' to the declaration to emit the Objective-C entrypoint in Swift 4 and suppress this message 2017-09-14 09:26:27.702076+0300 x[1885:288332] *** /Users/x/Desktop/x/x/x/EPCalendarPicker/EPCalendarPicker.swift:254:5: implicit Objective-C entrypoint -[x.EPCalendarPicker collectionView:layout:sizeForItemAtIndexPath:] is deprecated and will be removed in Swift 4; add explicit '@objc' to the declaration to emit the Objective-C entrypoint in Swift 4 and suppress this message