I use UICollectionView to make a small app.
I just want to change Edit Menu when tap “longPress” but can not.
Ex. Change “Cut” to “Delete”.
I implement my ActionSheet like the code below.
But that’s not I want because I must implement ActionSheetDelegate outside the scope of UICollectionView.
I want to implement ActionSheet inside performAction method for easy to control.
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
UIActionSheetclass and show that whenlongPressaction is occurred.Here is the protocol document for UIActionSheet and the UIActionSheet class reference.