3

EKEventEditViewController 不支持被推送到 NavController 吗?请参阅附加的代码和错误。

我可以以模态方式呈现 EKEventEditViewController,但是当我尝试通过导航控制器推送时,出现以下错误:

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

代码是:

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

[self.navigationController pushViewController:addController animated:TRUE];   // ERROR HERE
4

3 回答 3

3

EKEventEditViewController 是 UINavigationController 的子类,所以它不能被推送到另一个 UINavigationController。

EKEventEditViewController 应该以模态方式呈现。

EKEventEditViewController 类参考

于 2011-11-03T07:01:47.453 回答
0

如果您正在寻找一些代码来启动 iPad-with-popover 实现:

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];

当用户完成或取消事件编辑时,您还需要包含此委托方法来执行您需要执行的任何操作:

- (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];
}

享受!

标记

于 2012-05-17T18:30:37.987 回答
0

对于未来的读者:

EKEventEditViewController 是一个 UINavigationController 所以你可以说:

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

// Set your properties here

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

这对我有用,但我不知道你是否可以为 Apple 做到这一点。

于 2013-09-10T16:27:47.830 回答