Greg
Greg

Reputation: 34838

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

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

Upvotes: 4

Views: 2235

Answers (3)

Gustaf Rosenblad
Gustaf Rosenblad

Reputation: 1922

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.

Upvotes: 0

mpemburn
mpemburn

Reputation: 2884

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

Upvotes: 0

holodnyalex
holodnyalex

Reputation: 791

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

EKEventEditViewController should be presented modally.

EKEventEditViewController Class Ref

Upvotes: 4

Related Questions