EKCalendarChooser new Calendar

99封情书 提交于 2019-12-10 11:49:22

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/9660419/ekcalendarchooser-new-calendar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!