因此,我已经创建了一个自定义视图,当单击UIMenuItem时,我希望在屏幕底部显示该视图。
我的ViewController.m中有:
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *translateItem = [[UIMenuItem alloc] initWithTitle:@"Translate" action:@selector(translateClicked:)];
[menuController setMenuItems:[NSArray arrayWithObject:translateItem]];相关的UITextView有一个带有方法(CustomTextView.m)的自定义UITextView:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(copy:)) return YES;
if (action == @selector(translateClicked:)) return YES;
return NO;
}
- (IBAction)translateClicked:(id)sender
{
NSLog(@"In Custom UITextView");
}这将“复制”和“翻译”显示为两个菜单选项。目前,当单击“翻译”时,我会得到“在自定义UITextView中”的日志。
是否有可能在ViewController.m中有一个方法来包含以下代码?
CustomPopUp *customView = [CustomPopUp customView];
[self.view addSubview:customView];发布于 2014-02-03 19:33:45
我自己解决了这个问题:
通过删除行:
if (action == @selector(translateClicked:)) return YES;在CustomTextView.m中
并添加:
- (void) translateClicked: (id) sender
{
NSLog(@"In ViewController");
}在ViewController.m。这允许我在原始UIViewController中运行方法。
https://stackoverflow.com/questions/21526114
复制相似问题