我正在使用a UIMenuItem在UICollectionView单元长按中执行自定义操作.这与iOS 6完美配合,但现在我将我的应用程序转换为iOS 7和Xcode 5,但它无法正常工作.自定义项目未显示.
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 …所以,我不确定我在这里做错了什么,但是我有一个UIViewController,它上面有一个UICollectionView.在UIViewController的viewDidLoad方法中,我执行以下操作,它不会向显示的弹出窗口添加任何自定义菜单项.
UIMenuItem *removeItem = [[UIMenuItem alloc] initWithTitle:@"Remove" action:@selector(handleRemoveItem:)];
UIMenuItem *duplicateItem = [[UIMenuItem alloc] initWithTitle:@"Duplicate" action:@selector(handleDuplicateItem:)];
[[UIMenuController sharedMenuController] setMenuItems:@[removeItem, duplicateItem]];
[removeItem release];
[duplicateItem release];
我确实在所有情况下都设置了collectionView:shouldShowMenuForItemAtIndexPath:并collectionView:canPerformAction:forItemAtIndexPath:withSender:返回YES,但无论如何,只会显示剪切,复制和粘贴.
我没有完全实现这一点,还是我没有做到这一点?
PS - 我确实在整个谷歌中看到了尽可能多的例子,我没有找到任何有用的东西.
我有一个包含集合视图的标准视图控制器.
我正在使用从自定义子类创建的自定义单元格填充集合视图UICollectionViewCell.
从集合视图单元类中调用集合视图类中的方法的最佳实践是什么?
为什么在我的集合视图单元类中没有调用以下init,我认为当collectionView类创建我的单元格时会调用它.
(id)initWithFrame:(CGRect)frame
我想这样做的原因是因为我正在删除集合视图单元格,删除函数位于集合视图单元格类中.我想在删除时播放声音,而宁愿在集合视图控制器类中初始化声音,而不是每个单元格.