0

I am developing a date-based application. I have implemented a calendar in my Swift project. It works on ios 8 perfectly but in ios 7 is not working. I have just integrated MBCalendarKit to my Swift project. There should be a calendar view in the ViewController. You can find my project from this link Calendar Integration Project Here is my basic code. I think there should be child-parent navigation problem. Please help me to solve this problem.

class ViewController: UIViewController, CKCalendarViewDelegate, CKCalendarViewDataSource {



var data : NSMutableDictionary
var calendar = CKCalendarViewController()
var newdata = CKCalendarView()

required init(coder aDecoder: NSCoder) {

    data = NSMutableDictionary()
    super.init(coder: aDecoder)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    self.data = NSMutableDictionary()
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad() {
    super.viewDidLoad()

    calendar.dataSource = self
    //        self .addChildViewController(calendar)
    //        self.view.addSubview(calendar.view)
    //        calendar .didMoveToParentViewController(self)
    //        targetController.view.superview.center = self.view.center;

    self.parentViewController?.presentViewController(calendar, animated: true, completion: nil)

    let title : NSString = NSLocalizedString("Add Swift Demo", comment: "")
    let date : NSDate = NSDate(day: 14, month: 4, year: 2016)
    let event : CKCalendarEvent = CKCalendarEvent(title: title as String, andDate: date, andInfo: nil)
    self.data[date] = [event]
}
func calendarView(calendarView: CKCalendarView, willSelectDate date: NSDate) {
    print("will select called")
}
func calendarView(calendarView: CKCalendarView, didSelectDate date: NSDate) {

    print("didselect date called")
    let ntview = noteview(nibName: "noteview", bundle: nil)
    self.navigationController?.pushViewController(ntview, animated: true)
    //self.navigationController?.popViewControllerAnimated(false)
}
func calendarView(calendarView: CKCalendarView!, eventsForDate date: NSDate!) -> [AnyObject]! {

    return self.data.objectForKey(date) as [AnyObject]!
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
kalpesh
  • 1,285
  • 1
  • 17
  • 30
  • What exactly isnt working on ios 7? – Just a coder Apr 20 '16 at 16:07
  • in ios 7 i am not able to present calendar but in ios 8 it present very well. and even i did not get any kind of warnig or error. – kalpesh Apr 21 '16 at 04:06
  • Have you checked the PodFile you are using? does it say this--> platform :ios, '8.0' ? And also, Considering that MB Calendar has so many issues opened, why are you using it in the first place. Why not use an use the top updated ones? --> https://cocoapods.org/?q=calenda – Just a coder Apr 21 '16 at 06:09

1 Answers1

0

As of version 5, MBCalendarKit requires iOS 8.0 or higher. If you're looking for iOS 7 support, you can try dragging the files straight into your Xcode project.

Version 5 adds a lot of improvements for Swift integration. I audited the code for nullability, and added NS_SWIFT_NAME() where appropriate.

Disclaimer: I wrote and maintain MBCalendarKit.

Moshe
  • 57,511
  • 78
  • 272
  • 425