EKCalendarChooser new Calendar

2019-06-14 12:49发布

Is it possible to show the enable adding new calendars in EKCalendarChooser just like the default iPhone Calendar app shows the + in the upper left corner and allows you to define you calendars?

2条回答
家丑人穷心不美
2楼-- · 2019-06-14 13:20

After a lot of trial and errors, I finally got it:

var calendarChooser: EKCalendarChooser!
var navController: UINavigationController!

func setup () {
    calendarChooser =  EKCalendarChooser(
        selectionStyle: EKCalendarChooserSelectionStyleMultiple,
        displayStyle: EKCalendarChooserDisplayAllCalendars,
        entityType: EKEntityTypeEvent,
        eventStore: zeitplanController.cache.eventStore)
    // DON'T DO THE FOLLOWING:
    // calendarChooser.editing = false
    navController = UINavigationController(rootViewController: calendarChooser)
    calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit, target: self, action: "startEditing")
}

func startEdit () {
    calendarChooser.editing = true
    calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "endEdit") }

func endEdit () {
    calendarChooser.editing = false
    calendarChooser.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit, target: self, action: "startEdit")
}

This, put in a UIPopoverController shows the standard Calendar Chooser Dialog including editing functionality, like in the original calendar app.

@Apple: please do us the favor and update the documentation, to make our lives easier

查看更多
ら.Afraid
3楼-- · 2019-06-14 13:40

I've been seeking the same ready-to-use solution for almost a day and no luck so far..

The good thing is, however, that you can call

[yourEKCalendarChooserInstance setEditing:YES];

And It will show you the "Add Calendar" row

But the bad thing is that nothing happens on click/select. That's all I found out so far

UPDATE:

this code worked for me (test only on simulator so far):

EKEventStore *store = [[[EKEventStore alloc] init] autorelease];
EKCalendarChooser *chooser = [[EKCalendarChooser alloc] initWithStyle:EKCalendarChooserSelectionStyleSingle displayStyle:EKCalendarChooserDisplayWritableCalendarsOnly eventStore:store];
[chooser setEditing:YES];
[chooser setShowsDoneButton:YES];
[chooser setShowsCancelButton:YES];
UINavigationController *modalController = [[UINavigationController alloc] initWithRootViewController:chooser];
[self presentViewController:modalController animated:YES completion:nil];

In addition, of course, you will need to provide delegate for done/cancel buttons.

查看更多
登录 后发表回答