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