4

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?

user826955
  • 3,137
  • 2
  • 30
  • 71

1 Answers1

6

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

dvc.selectedCalendars = [[NSSet alloc] init];
Mark
  • 86
  • 1
  • 2
  • Are you sure about this? I don't have to do this in single selection mode. Will try when at home though. – user826955 Aug 20 '12 at 12:23
  • I did this, but it did help. I wasn't initializing the NSSet variable earlier. Either way, using the multiple selection feature still doesn't work for me. I output the selected calendars at the instance they are selected, but when selected, null null null 0 0 0 pops up everywhere, I am doing alot of checks to see where they data is but NOTHING is being referenced. I feel like apple just forgot to implement the EKCalendarChooserSelectionStyleMultiple type or something. Because it clearly isn't returning any clicked cells. – jsetting32 Apr 30 '13 at 20:20
  • 1
    2015, still need to alloc init the `selectedCalendars` in order for the multiple selection style to work properly. – Alex Dec 03 '15 at 08:29