【问题标题】:How present UIMenuController and UIAlertController at the same time?如何同时呈现 UIMenuController 和 UIAlertController?
【发布时间】:2018-07-22 17:04:30
【问题描述】:

我正在尝试下一个方法:

Message *message = self.messagesArray[indexPath.row];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:LocalizedString(@"FirstAction")
                                                                         message:@""
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *editMessage = [UIAlertAction actionWithTitle:LocalizedString(@"SecondAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:editMessage];
UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:LocalizedString(@"ThirdAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:forwardMessage];
UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:LocalizedString(@"DeleteMessage") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:deleteMessage];
[self setSourceViewForAlertController:alertController];
[self presentViewController:alertController animated:YES completion:nil];
[self createMenuForMessage:message];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];

所以,我的目标是同时为 UICollectionViewCell 和 UIMenuController 提供 alertcontroller。

像这样:

【问题讨论】:

  • 显示您的要求
  • 请详细说明....
  • 你需要同时显示两个东西???你为什么要这样做?
  • @ReinierMelian 只是为用户提供更多选择。如果不可能,我会寻找其他 UX 决策。
  • @Viktorianec 你的问题到底是什么,我可以显示 actionSheet 和菜单,但可以触摸菜单,直到 actionSheet 被解除

标签: ios objective-c uialertcontroller uimenucontroller


【解决方案1】:

您的问题与您在哪里显示您的 UIMenuController 有关,您必须考虑到 UIView 必须实现返回 YEScanBecomeFirstResponder 方法

- (IBAction)action:(id)sender {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
                                                                             message:@""
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *editMessage = [UIAlertAction actionWithTitle:@"Edit" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    [alertController addAction:editMessage];
    UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:@"Move" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    [alertController addAction:forwardMessage];
    UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    [alertController addAction:deleteMessage];
    [self presentViewController:alertController animated:YES completion:nil];
    [[UIMenuController sharedMenuController] setTargetRect:self.view.bounds inView:self.view];
    [[UIMenuController sharedMenuController] setArrowDirection:UIMenuControllerArrowDefault];
    [[UIMenuController sharedMenuController] setMenuItems:@[[[UIMenuItem alloc]initWithTitle:@"test" action:@selector(didReceiveMemoryWarning)]]];
    [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}

-(BOOL)canBecomeFirstResponder{
    return true;
}

【讨论】:

  • canBecomeFirstResponder 给我一个崩溃:“由于未捕获的异常 'UIViewControllerHierarchyInconsistency' 而终止应用程序,原因:'子视图控制器: 应该有父视图控制器:
  • @Viktorianec 你能给我一些你的设置细节吗?
  • 我使用自定义 inputView,所以我认为它会导致崩溃。这就是为什么我不能用你提供的方式展示的原因。但我认为你给出了一个正确的答案......无论如何这不是我的情况的解决方案。
  • @Viktorianec 但您的自定义输入视图是 UIView 子类?
  • 我将 UIPageController 与 Stickers 一起使用
猜你喜欢
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 2020-10-01
  • 1970-01-01
  • 2014-12-20
相关资源
最近更新 更多