简体   繁体   English

如何在UICollectionView中更改编辑菜单?

[英]How to change Edit Menu in UICollectionView?

I use UICollectionView to make a small app. 我使用UICollectionView制作一个小应用程序。 I just want to change Edit Menu when tap "longPress" but can not. 我只想在点击“longPress”时更改编辑菜单但不能。

Ex. 防爆。 Change "Cut" to "Delete". 将“剪切”更改为“删除”。


I implement my ActionSheet like the code below. 我像下面的代码一样实现我的ActionSheet。 But that's not I want because I must implement ActionSheetDelegate outside the scope of UICollectionView. 但这不是我想要的,因为我必须在UICollectionView的范围之外实现ActionSheetDelegate。

I want to implement ActionSheet inside performAction method for easy to control. 我想在performAction方法中实现ActionSheet以便于控制。
Any suggestion? 有什么建议吗? Thank you! 谢谢!

- (BOOL)collectionView:(QSCollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath{
    QSCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    UIActionSheet *deleteButton = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"Remove: %@",[collectionView.collectionData objectAtIndex:indexPath.row]] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"OK" otherButtonTitles: nil];
    [deleteButton showFromRect:CGRectMake(0, 57, 57, 20) inView:cell animated:NO];
    return YES;
}
-(BOOL)collectionView:(QSCollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
    return YES;
}
-(void)collectionView:(QSCollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
}
//ActionSheet
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"Delete");
            break;
        default:
            break;
    }
}

You should implement your own UIActionSheet class and show that when longPress action is occurred. 您应该实现自己的UIActionSheet类,并在发生longPress操作时显示。

Here is the protocol document for UIActionSheet and the UIActionSheet class reference . 这是UIActionSheetUIActionSheet类引用协议文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM