Jak wyświetlić niestandardowy UIMenuItem dla UITableViewCell?
Chcę UIMenuController, który pojawia się, gdy długo naciśnij UITableViewCell, aby wyświetlić niestandardowe UIMenuItems.
Ustawiłem niestandardowy element w viewDidLoad
UIMenuItem *testMenuItem = [[UIMenuItem alloc] initWithTitle:@"Test" action:@selector(test:)];
[[UIMenuController sharedMenuController] setMenuItems: @[testMenuItem]];
A potem ustawiam wszystkie odpowiednie metody delegowania.
- (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;
}
Ale wszystko, co robi, to pokazanie elementu „Kopiuj”, ponieważ zezwalam na to i mój własny element. Jednak niestandardowy przedmiot nie pojawi się.
Zdaję sobie sprawę, że mógłbym dodać urządzenie rozpoznawania gestów do samej komórki, ale tego rodzaju pokonuje cel współużytkowanej instancji UIMenuController, prawda?