[英]EKEventViewController wont show Edit Button on iOS 13
i got a simple app where i want to present an event within an EKEventViewController.我有一个简单的应用程序,我想在 EKEventViewController 中显示一个事件。
// the button action which validates if the event store access is granted and presents the given alert if true
@IBAction func actionButtonShowPopover(_ sender: Any) {
eventStore.requestAccess(to: .event) { (granted, _) in
guard granted else { return }
let event = self.generateAndSaveEvent()
self.presentEventViewController(withEvent: event)
}
}
// creates and tries to save an sample even and returns it
private func generateAndSaveEvent() -> EKEvent {
let event = EKEvent(eventStore: eventStore)
event.title = "Event Title"
event.startDate = Date()
event.endDate = Date().addingTimeInterval(1800)
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.save(event, span: .thisEvent)
} catch(let error) {
print(error)
}
return event
}
// displays an EKEventViewController with our newly created event within an popover
private func presentEventViewController(withEvent event: EKEvent) {
DispatchQueue.main.async {
let eventVC = EKEventViewController()
eventVC.event = event
eventVC.allowsEditing = true
eventVC.modalPresentationStyle = .popover
eventVC.popoverPresentationController?.sourceView = self.buttonShowPopover
eventVC.popoverPresentationController?.sourceRect = self.buttonShowPopover.frame.offsetBy(dx: 0, dy: -10)
eventVC.popoverPresentationController?.backgroundColor = .white
eventVC.popoverPresentationController?.permittedArrowDirections = .up
self.present(eventVC, animated: false, completion: nil)
}
}
i created an event as shown in the code above and simply displaying it within the popover view controller.我创建了一个如上面代码所示的事件,并简单地在弹出视图 controller 中显示它。 since ios 13 i got a different result:
由于 ios 13 我得到了不同的结果:
iOS 12.4 with edit button iOS 12.4 带编辑按钮
iOS 13 without edit button iOS 13 不带编辑按钮
is there any chance i'm missing changes from iOS12 -> iOS13?我有没有可能错过 iOS12 -> iOS13 的更改? thanks upfront - i'm grateful for any advice!
预先感谢 - 我很感激任何建议!
Edit button has moved to navigation bar in iOS 13. You need to present it without popover style.编辑按钮已移至 iOS 13 中的导航栏。您需要在没有弹出框样式的情况下呈现它。
In my app, that's been around for a while, I was experiencing the same problem with the edit button no longer appearing in iOS13.在我的应用程序中,这已经存在了一段时间,我遇到了同样的问题,iOS13 中不再出现编辑按钮。 Unlike other users, my
EKEventViewController
was already wrapped in a navigation controller, so it wasn't that issue.与其他用户不同,我的
EKEventViewController
已经包含在导航 controller 中,所以不是那个问题。
Several hours of going down rabbit holes, I've found a fix.经过几个小时的兔子洞,我找到了解决办法。 Here's where the problems were occurring in my app:
这是我的应用程序中出现问题的地方:
Debugging just before opening the view, the EKEvent
object I was trying to edit didn't have a value set for .eventIdentifier
.在打开视图之前进行调试,我试图编辑的
EKEvent
object 没有为.eventIdentifier
设置值。 Reading into this, it seems this property is lazy loaded, so not being able to retrieve the value here suggests the link between the EKEvent
and the EKStore
I used to fetch it has been lost somewhere in the application lifecycle.读到这里,似乎这个属性是延迟加载的,因此无法在此处检索值表明
EKEvent
和我用来获取它的EKStore
之间的链接在应用程序生命周期的某个地方丢失了。 This is a change that been introduced somewhere along the iOS/Swift upgrade journey - I can't pin down the change that has caused this.这是在 iOS/Swift 升级过程中某处引入的更改 - 我无法确定导致此的更改。
By accessing the EKEvent.eventIdentifier
at the time I first retrieved the EKEvent
, I now had this identifier for later use通过在我第一次检索
EKEvent
EKEvent.eventIdentifier
我现在有了这个标识符供以后使用
Before presenting the EKEventViewController, I fetch a fresh copy of this event and use the fresh event in the controller:在展示 EKEventViewController 之前,我获取了该事件的新副本并使用 controller 中的新事件:
let freshEvent = store.event(withIdentifier: staleEvent.eventIdentifier)
eventViewController.event = freshEvent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.