我正在尝试另一种方法:

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。

像这样:
ios - 如何同时显示UIMenuController和UIAlertController?-LMLPHP

最佳答案

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

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

ios - 如何同时显示UIMenuController和UIAlertController?-LMLPHP

关于ios - 如何同时显示UIMenuController和UIAlertController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48747973/

10-10 23:14