EKEventEditViewController 不支持推送到 NavController 吗?请参阅代码 &附加错误

发布于 2024-12-13 05:22:52 字数 644 浏览 1 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光礼记 2024-12-20 05:22:52

EKEventEditViewController 是 UINavigationController 的子类,因此不能将其推送到另一个 UINavigationController。

EKEventEditViewController 应以模态方式呈现。

EKEventEditViewController 类参考

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

EKEventEditViewController should be presented modally.

EKEventEditViewController Class Ref

紙鸢 2024-12-20 05:22:52

如果您正在寻找一些代码来快速启动 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];
}

享受吧!

标记

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

两相知 2024-12-20 05:22:52

对于未来的读者:

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

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

// Set your properties here

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文