我正在像这样在辅助类中展示我的EKEventEditViewController
:
func showAddAppointmentController(withDate date:Date) {
let eventVC = EKEventEditViewController()
eventVC.editViewDelegate = self
eventVC.eventStore = eventStore
eventVC.event?.title = "Test appointment"
eventVC.event?.startDate = date
eventVC.event?.endDate = date.addingTimeInterval(3600)
UIApplication.shared.keyWindow?.rootViewController?.present(eventVC, animated: true, completion: nil)
}
一切正常,显示控制器,但是一旦我按下“添加”或“取消”,除了以下控制台输出,什么都没有发生:
[EKCalendarItemLocationInlineEditItem isSubitemAtIndexSaveable:] - Location Inline Edit Item didn't have a text label on its non conference location cell; will return NO
我已经按如下方式实现了委托,但是未调用该方法(不打印,并且断点也不起作用)
extension CalendarHelper : EKEventEditViewDelegate {
func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
print("Delegate called!")
controller.dismiss(animated: true) {
self.delegate?.didFinish()
}
}
}
答案 0 :(得分:1)
好吧,错误出在别的地方,我很糟糕。我是在代码中创建CalendarHelper的,而不是将其作为类的属性保存的,因此,一旦显示了日历,该帮助器即被删除,不能再作为委托使用。
private var calendarHelper:CalendarHelper?
override func viewDidLoad() {
super.viewDidLoad()
calendarHelper = CalendarHelper(delegate: self)
}
func showCalendar() {
calendarHelper.showCalendar()
}
代替
func showCalendar() {
CalendarHelper(delegate: self).showCalendar()
}