如何同时呈现 UIMenuController 和 UIAlertController?
How present UIMenuController and UIAlertController at the same time?
我正在尝试下一种方式:
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。
像这样:
您的问题与您在何处展示您的 UIMenuController
有关,您必须考虑到 UIView
必须实施返回 YES
[= 的 canBecomeFirstResponder
方法16=]
- (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;
}
我正在尝试下一种方式:
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。
像这样:
您的问题与您在何处展示您的 UIMenuController
有关,您必须考虑到 UIView
必须实施返回 YES
[= 的 canBecomeFirstResponder
方法16=]
- (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;
}