gpt4 book ai didi

ios - 没有导航栏时,如何在 EKEventViewController 中获取 "Done"或 "Back"按钮?

转载 作者:可可西里 更新时间:2023-11-01 05:54:05 25 4
gpt4 key购买 nike

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

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

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

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

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

但是这个解决方案不是很优雅,因为当我在事件 View 中按下“后退”按钮时,在事件 View 全部退出之前,导航栏并没有被删除(它显示在我的事件 ListView 的顶部)屏幕。

如何解决这个问题?最好的选择是以某种方式在事件 View 中得到一个后退按钮,我可以在这里使用第一个代码(这样我就可以避免显示导航栏),并且 View 可以滑回屏幕底部按下时。

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

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

最佳答案

看起来您根本不需要隐藏导航栏!你能解释更多为什么你需要隐藏或显示导航栏吗?这将是隐藏或显示模型 View 的简单解决方案。

//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

- (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 编辑

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

Code Example -

关于ios - 没有导航栏时,如何在 EKEventViewController 中获取 "Done"或 "Back"按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23698060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com