EKEventEditViewController添加和取消按钮无响应

时间:2017-11-08 14:45:22

标签: objective-c calendar eventkit ekevent ekeventkit

我正在尝试使用EKEventEditViewController添加日历活动。我已正确设置了EKEventEditViewController EKEventStoreEKEvent及其editViewDelegate作为展示视图控制器。 EKEventEditViewController正确显示,但是当我按下任何一个'添加'或者'取消',didCompleteWithAction未在EKEventEditViewDelegate中调用。但是,我确实得到了这个错误(尽管没有崩溃):

[EKCalendarItemLocationInlineEditItem isSubitemAtIndexSaveable:] - Location Inline Edit Item didn't have a text label on its non conference location cell; will return NO

您可以在EKCalendarItemLocationInlineEditItem框架中看到EventKitUI CREATE TABLE `notification_types` ( `Id` BIGINT(16) NOT NULL AUTO_INCREMENT, `TypeName` VARCHAR(80) NOT NULL, `InsertedDttm` DATETIME NULL, `InsertedBy` BIGINT(16) NULL, `UpdatedDttm` DATETIME NULL, `UpdatedBy` BIGINT(16) NULL, PRIMARY KEY (`Id`)); CREATE TABLE `notification_types_permission` ( `Id` BIGINT(16) NOT NULL AUTO_INCREMENT, `NotificationTypes_ID` BIGINT(16) NOT NULL, `permissions_ID` int(11) NOT NULL, PRIMARY KEY (`Id`), FOREIGN KEY (NotificationTypes_ID) REFERENCES `frontoffice`.notification_types(id), FOREIGN KEY (permission_Id) REFERENCES `frontoffice`.`permission`(id)); public class NotificationTypes { @Id private Long id; private String typeName; @Temporal(TemporalType.TIMESTAMP) private Date insertedDttm; private Long insertedBy; @Temporal(TemporalType.TIMESTAMP) private Date updatedDttm; private Long updatedBy; @OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER) private List<RLPermissions> permissions; }

这似乎与位置有关,但我似乎无法弄明白。有没有人遇到过这个错误,或者有任何关于如何进一步调试的提示?谢谢!我正在运行iOS 11和Xcode 9.0.1。

2 个答案:

答案 0 :(得分:2)

在展示editViewDelegate之前,您似乎没有设置EKEventEditViewController。没有代表,按钮'添加'和'取消'不响应。

创建EventView并呈现(Swift)

let eventView: EKEventEditViewController = EKEventEditViewController()
eventView.event = event
eventView.editViewDelegate = self
eventView.eventStore = eventStore

present(eventView, animated: true) { }

ObjC

EKEventEditViewController *eventView = [[EKEventEditViewController alloc] init];
eventView.event = event;
eventView.editViewDelegate = self;
eventView.eventStore = eventStore;

[self presentViewController:eventView animated:true completion: nil];

答案 1 :(得分:1)

如果您已经设置了代表,但仍然遇到令人恐惧的[EventEditor] -[EKCalendarItemLocationInlineEditItem isSubitemAtIndexSaveable:] - Location Inline Edit Item didn't have a text label on its non conference location cell; will return NO,则可能没有设置EKEventEditViewController.eventStore

这是一个有效的示例代码,显示了如何正确配置EKEventEditViewController

func showNewEvent(askPermission: Bool) {
    let store = EKEventStore()
    if askPermission {
        store.requestAccess(to: .event) { (granted, error) in
            if granted {
                DispatchQueue.main.async {
                    self.showNewEvent(askPermission: false)
                }
            }
        }
        return
    }

    let event = EKEvent(eventStore: store)
    event.title = "New event name"
    event.notes = "Some notes"
    event.availability = .busy
    event.isAllDay = ...
    event.startDate = ...
    event.endDate = ...
    event.structuredLocation = ...

    let vc = EKEventEditViewController()
    vc.event = event
    vc.eventStore = store // <-- this needs to be the same event store you used for EKEvent
    vc.editViewDelegate = self
    present(vc, animated: true, completion: nil)
}

此代码的灵感来自这篇神奇的帖子https://dev.to/nemecek_f/how-to-use-ekeventeditviewcontroller-in-swift-to-let-user-save-event-to-ios-calendar-d8