@@ -70,9 +70,10 @@ - (void)viewDidLoad
70
70
action: @selector (receiveMessagePressed: )];
71
71
72
72
/* *
73
- * Register custom menu actions for cells
73
+ * Register custom menu actions for cells.
74
74
*/
75
- [JSQMessagesCollectionViewCell registerMenuAction: @selector (delete: )];
75
+ [JSQMessagesCollectionViewCell registerMenuAction: @selector (customAction: )];
76
+ [UIMenuController sharedMenuController ].menuItems = @[ [[UIMenuItem alloc ] initWithTitle: @" Custom Action" action: @selector (customAction: )] ];
76
77
77
78
78
79
/* *
@@ -512,9 +513,11 @@ - (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collection
512
513
513
514
#pragma mark - UICollectionView Delegate
514
515
516
+ #pragma mark - Custom menu items
517
+
515
518
- (BOOL )collectionView : (UICollectionView *)collectionView canPerformAction : (SEL )action forItemAtIndexPath : (NSIndexPath *)indexPath withSender : (id )sender
516
519
{
517
- if (action == @selector (delete : )) {
520
+ if (action == @selector (customAction : )) {
518
521
return YES ;
519
522
}
520
523
@@ -523,14 +526,26 @@ - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)
523
526
524
527
- (void )collectionView : (UICollectionView *)collectionView performAction : (SEL )action forItemAtIndexPath : (NSIndexPath *)indexPath withSender : (id )sender
525
528
{
526
- if (action == @selector (delete : )) {
527
- NSLog ( @" Did receive delegate action %@ " , NSStringFromSelector (action)) ;
529
+ if (action == @selector (customAction : )) {
530
+ [ self customAction: sender] ;
528
531
return ;
529
532
}
530
533
531
534
[super collectionView: collectionView performAction: action forItemAtIndexPath: indexPath withSender: sender];
532
535
}
533
536
537
+ - (void )customAction : (id )sender
538
+ {
539
+ NSLog (@" Custom action received! Sender: %@ " , sender);
540
+
541
+ [[[UIAlertView alloc ] initWithTitle: @" Custom Action"
542
+ message: nil
543
+ delegate: nil
544
+ cancelButtonTitle: @" OK"
545
+ otherButtonTitles: nil ]
546
+ show ];
547
+ }
548
+
534
549
535
550
536
551
#pragma mark - JSQMessages collection view flow layout delegate
0 commit comments