I'm using a UIMenuItem
to perform a custom action in UICollectionView
cell long press.
this worked perfectly with iOS 6, but now I am converting my application to iOS 7 and Xcode 5 and it don't work. The custom item do not shown.
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Unfavorite"
action:@selector(unFavorite:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:menuItem]];
[UIMenuController sharedMenuController].menuVisible = YES;
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
{
//do not show default itens like copy, paste....
[self becomeFirstResponder];
return NO;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
// The selector(s) should match your UIMenuItem selector
if (action == @selector(unFavorite:)) {
return YES;
}
return NO;
}
- (void)collectionView:(UICollectionView *)collectionView
performAction:(SEL)action
forItemAtIndexPath:(NSIndexPath *)indexPath
withSender:(id)sender {
}
- (BOOL)collectionView:(UICollectionView *)collectionView
shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
myIndexPath = indexPath;
return YES;
}