我使用 UICollectionView 来制作一个小应用程序。我只想在点击“longPress”时更改编辑菜单但不能。
前任。将“剪切”更改为“删除”。
我像下面的代码一样实现我的 ActionSheet。但这不是我想要的,因为我必须在 UICollectionView 范围之外实现 ActionSheetDelegate。
我想在performAction
方法内部实现 ActionSheet 以便于控制。
有什么建议吗?谢谢!
- (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;
}
}