在 CalendarKit 中创建新事件

Create new event in CalendarKit

在我的应用程序中,我尝试添加功能以在按下空 space 时使用 CalendarKit 创建新事件,但我找不到该怎么做。

我知道这是可能的,因为您可以在 demo app:

我已经尝试将此添加到我的应用代码中:

override func create(event: EventDescriptor, animated: Bool = false) {
    self.events.append(event) // self.events is my events data source
}

但是它没有用,事实上,当我长按一个空的 space 时它甚至都不会被调用。

我也尝试查看源代码,但我一无所获。我怎样才能做到这一点?提前致谢

override func dayView(dayView: DayView, didLongPressTimelineAt date: Date) {
    let newEvent = Event()
    
    newEvent.startDate = date
    newEvent.endDate = date.addingTimeInterval(3600)
    
    // Customize your event...
    newEvent.text = randomName() // A function that generates a new random name that haven't been used before.
    
    self.create(event: newEvent)
}

override func create(event: EventDescriptor, animated: Bool = false) {
    super.create(event: event, animated: animated)
    self.events.append(event)
}

override func dayView(dayView: DayView, didUpdate event: EventDescriptor) {
    for (index, eventFromList) in events.enumerated() {
        if eventFromList.text == event.text {
            events[index] = event
        }
    }
    self.endEventEditing()
    self.reloadData()
}

请确保每个 Event 都有自己唯一的名称,否则将无法正常工作