3

does EKEventEditViewController not support being pushed to a NavController? See code & error attached.

I can present the EKEventEditViewController modally fine, BUT when I try to push via the nav controller I get the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

Code is:

EKEventEditViewController *addController = [[[EKEventEditViewController alloc] initWithNibName:nil bundle:nil] autorelease];
addController.eventStore = self.eventStore;
addController.editViewDelegate = self;

[self.navigationController pushViewController:addController animated:TRUE];   // ERROR HERE
Greg
  • 34,042
  • 79
  • 253
  • 454

3 Answers3

3

EKEventEditViewController is subclass of UINavigationController, so it can't be pushed to another UINavigationController.

EKEventEditViewController should be presented modally.

EKEventEditViewController Class Ref

holodnyalex
  • 761
  • 5
  • 8
  • thanks - the issue I've then got if this is the case is here :( http://stackoverflow.com/questions/7991305/presentmodalviewcontroller-is-taking-over-whole-ipad-screen-not-just-right-hand – Greg Nov 03 '11 at 07:09
0

In case you're looking for some code to jumpstart an iPad-with-popover implementation:

EKEventStore *eventStore [[EKEventStore alloc] init];
EKEventEditViewController *eventController = [[EKEventEditViewController alloc] init];
eventController.editViewDelegate = self; 
eventController.eventStore = eventStore;

EKEvent *event  = [EKEvent eventWithEventStore: eventStore];
event.title     = @"New Event";
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval: 60 * 60 sinceDate: event.startDate];
eventController.event = event;

/* You can add EKEventEditViewController directly to the popover -- this had me baffled for _hours_ */
popover = [[UIPopoverController alloc] initWithContentViewController: eventController];

You will also want to include this delegate method to do whatever you need to when the user completes or cancels event editing:

- (void) eventEditViewController: (EKEventEditViewController *)controller didCompleteWithAction: (EKEventEditViewAction)action 
{
    EKEvent *thisEvent = controller.event;

    switch (action) {
        case EKEventEditViewActionCanceled:
            NSLog(@"Canceled action");
            break;

        case EKEventEditViewActionSaved:
            NSLog(@"Saved action: %@", thisEvent.startDate);
            break;

        case EKEventEditViewActionDeleted:
            NSLog(@"Deleted action");
            break;

        default:
            break;
    }

    [popover dismissPopoverAnimated: YES];
}

Enjoy!

Mark

mpemburn
  • 2,776
  • 1
  • 35
  • 41
0

For future readers:

EKEventEditViewController is a UINavigationController so you can just say:

EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];

// Set your properties here

[self.navigationController pushViewController:controller.viewControllers[0] animated:YES];

This works for me, but I don't know if you can do this for Apple.

Gustaf Rosenblad
  • 1,902
  • 2
  • 25
  • 45