gpt4 book ai didi

swift - 如何将 MBCalendarkit 集成到我的 Swift 项目?

转载 作者:行者123 更新时间:2023-11-30 13:29:51 25 4
gpt4 key购买 nike

我正在开发一个基于日期的应用程序。我在我的 Swift 项目中实现了一个日历。它在 ios 8 上完美运行,但在 ios 7 上不起作用。我刚刚将 MBCalendarKit 集成到我的 Swift 项目中。 ViewController 中应该有一个日历 View 。您可以从此链接找到我的项目 Calendar Integration Project这是我的基本代码。我认为应该存在子父导航问题。请帮我解决这个问题。

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.
}
*/

}

最佳答案

从版本 5 开始,MBCalendarKit 需要 iOS 8.0 或更高版本。如果您正在寻找 iOS 7 支持,您可以尝试将文件直接拖到您的 Xcode 项目中。

版本 5 添加了许多针对 Swift 集成的改进。我审核了代码的可空性,并在适当的地方添加了 NS_SWIFT_NAME()

免责声明:我编写并维护 MBCalendarKit。

关于swift - 如何将 MBCalendarkit 集成到我的 Swift 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36692561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com