Я хочу, чтобы UIMenuController появлялся, когда я долгое время нажимаю UITableViewCell для отображения пользовательских UIMenuItems.
Я настраиваю пользовательский элемент в viewDidLoad
UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test:)];
[[UIMenuController sharedMenuController] setMenuItems: @[testMenuItem]];
И затем я установил все правильные методы делегата.
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return (action == @selector(copy:) || action == @selector(test:));
}
- (BOOL)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
// do stuff
}
return YES;
}
Но все, что он делает, показывает элемент "Копировать", так как я разрешаю только его и свой пользовательский элемент. Пользовательский элемент, однако, не будет отображаться.
Я понимаю, я мог бы добавить распознаватель жестов к самой ячейке, но этот вид побеждает цель общего экземпляра UIMenuController, не так ли?