如何获得“完成"通知或“返回"没有导航栏时,在EKEventViewController中单击按钮? [英] How to get a "Done" or "Back" button in an EKEventViewController when no having a navigation bar?

查看:160
本文介绍了如何获得“完成"通知或“返回"没有导航栏时,在EKEventViewController中单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用程序中有一个日历事件列表,单击该事件将在EKEventViewController中打开.这是我的代码:

I have a list of calendar events in my iOS app, that is to be opened in an EKEventViewController when clicked. Here is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EKEventViewController *eventViewController = [EKEventViewController new];
    eventViewController.event = [self.events objectAtIndex:[indexPath row]];
    [self presentViewController:eventViewController animated:YES completion:nil];
}

事件视图从屏幕底部正确弹出,但是我无法返回事件列表!

The Event view correctly pops up from the bottom of the screen, but I have no way of going back to the list of events!

我正在使用导航控制器(但没有导航栏!),因此添加此代码使我能够返回到列表:

I am using a navigation controller (but no navigation bar!), so adding this code made me able to go back to the list:

-(void)viewDidAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EKEventViewController *eventViewController = [EKEventViewController new];
    eventViewController.event = [self.events objectAtIndex:[indexPath row]];
    [self.navigationController setNavigationBarHidden:NO];
    [self.navigationController pushViewController:eventViewController animated:YES];
}

但是此解决方案不是很好,因为当我在事件视图中按返回"按钮时,在事件视图全部退出之前,导航栏不会被删除(它显示在我的事件列表视图顶部).屏幕.

But this solution is not very elegant, because when I press the "Back" button in the event view, the navigation bar is not removed (it shows on top of my event list view) before the event view is all out of the screen.

如何解决此问题?最好的选择是在事件视图中以某种方式获得一个后退按钮,我可以将其与此处的第一个代码一起使用(因此,我将避免显示导航栏),并且该视图可以滑回到屏幕底部按下时.

How to fix this? The best option would have been to somehow got a back button in the event view that I could have used with the first code here (so I would avoid showing the navigation bar), and the view could just slide back to the bottom of the screen when pressed.

解决方案: 最终得到以下代码:

SOLUTION: Ended up with the following code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EKEventViewController *eventViewController = [EKEventViewController new];
    eventViewController.event = [self.events objectAtIndex:[indexPath row]];
    eventViewController.delegate = self;
    UINavigationController *navBar = [[UINavigationController new] initWithRootViewController:eventViewController];
    [self presentViewController:navBar animated:YES completion:nil];
}

- (void)eventViewController:(EKEventViewController *)controller didCompleteWithAction:(EKEventViewAction)action
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

推荐答案

看起来根本不需要隐藏导航栏!您能否进一步说明为什么需要隐藏或显示导航栏?这是隐藏或显示模型视图的简单解决方案.

Looks like you do not need to hide the navigation bar at all ! Can you explain more why you need to hide or show the nav bar ? This will be simple solution to hide or show the model view.

//EKEventListVC.m

// EKEventListVC.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
            EKEventViewController *pms = [EKEventViewController new];
            UINavigationController *nav = [[UINavigationController alloc]
                                           initWithRootViewController:pms];
            [self presentViewController:nav animated:YES completion:nil];
}

//EKEventViewController.m

// EKEventViewController.m

- (void)addRightButton
{
    UIButton *rightButton = // make your button
    [rightButton addTarget:self action:@selector(rightBtnActionDone:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    [self.navigationItem setRightBarButtonItem:barButtonItem];
}

//

- (void)rightBtnActionDone:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

//为EKEventKitUI编辑

// Edited For EKEventKitUI

-(void)eventEditViewController:(EKEventEditViewController *)controller
         didCompleteWithAction:(EKEventEditViewAction)action {

    switch (action) {
       case EKEventEditViewActionCanceled:
           // User tapped "cancel"
           break;
       case EKEventEditViewActionSaved:
           // User tapped "save"
           break;
       case EKEventEditViewActionDeleted:
           // User tapped "delete"
           break;
       default:
           break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

代码示例-

这篇关于如何获得“完成"通知或“返回"没有导航栏时,在EKEventViewController中单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆