EKCalendarChooser multiple selection does not work

2019-05-16 00:50发布

问题:

I'm trying to use EKCalendarChooser to get multiple calendars selected by the user. This is how I present the view:

EKCalendarChooser* dvc= [[[EKCalendarChooser alloc] initWithSelectionStyle:EKCalendarChooserSelectionStyleMultiple displayStyle:EKCalendarChooserDisplayAllCalendars eventStore:eventStore] autorelease];

dvc.selectedCalendars= self.selectedCalendars;
dvc.delegate= self;
dvc.contentSizeForViewInPopover= CGSizeMake(320.0, 480.0);

self.popOver= [[UIPopoverController alloc] initWithContentViewController:dvc];
[self.popOver release];
self.popOver.delegate= self;

UIBarButtonItem* item= sender;

[self.popOver presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

I get the calendarChooserSelectionDidChange message once I select one or more calendars, but every time the selectedCalendars property of the EKCalendarChooser is empty!

- (void)calendarChooserSelectionDidChange:(EKCalendarChooser *)calendarChooser
{
   NSLog(@"selected %d calendars", calendarChooser.selectedCalendars.count);
}

2012-02-26 12:50:39.137 MyApp[8604:707] selected 0 calendars
2012-02-26 12:50:42.100 MyApp[8604:707] selected 0 calendars

When I use EKCalendarChooserSelectionStyleSingle instead of EKCalendarChooserSelectionStyleMultiple, everything works fine and I will get the correct selected calendar through the selectedCalendars property.

Am I doing anything wrong, or is this a bug in EKCalendarChooser?

回答1:

If your self.selectedCalendars are nil you have to initialize the dvc.selectedCalendars with an valid but empty set.

dvc.selectedCalendars = [[NSSet alloc] init];