Note that there are some explanatory texts on larger screens.

plurals
  1. PODeleting cells from UICollectionView via NSNotification
    text
    copied!<p>I have a simple UICollectionView based app - one UICollectionView and a NSMutableArray based data model for simplicity.</p> <p>I can delete cells with no problem via the didSelectItemAtIndexPath: delegate method:</p> <pre><code>-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [self.data removeObjectAtIndex:[indexPath row]]; [self.collectionView deleteItemsAtIndexPaths:@[indexPath]]; } </code></pre> <p>However, I'm trying to add a delete option via a <code>UIMenuController</code> in a <code>UICollectionViewCell</code> subclass which is triggered via a <code>UILongPressGestureRecognizer</code> which all works fine and I successfully trigger an <code>NSNotification</code> </p> <pre><code>-(void)delete:(id)sender{ NSLog(@"Sending deleteme message"); [[NSNotificationCenter defaultCenter] postNotificationName:@"DeleteMe!" object:self userInfo:nil]; } </code></pre> <p>I catch it in my ViewController and call the following method:</p> <pre><code>-(void)deleteCell:(NSNotification*)note{ MyCollectionViewCell *cell = [note object]; NSIndexPath *path = nil; if((path = [self.collectionView indexPathForCell:cell]) != nil){ [self.data removeObjectAtIndex:[path row]]; [self.collectionView deleteItemsAtIndexPaths:@[path]]; } } </code></pre> <p>And it crashes on the deleteItemsAtIndexPaths: call</p> <pre><code>-[UICollectionViewUpdateItem action]: unrecognized selector sent to instance 0xee7eb10 </code></pre> <p>I've checked everything obvious - like the object from NSNotification and the indexPath created from the indexPathForCell: call and it all seems totally fine. It seems like I'm calling deleteItemsAtIndexPath: with the same information in both places, but for some reason it fails when it goes via the notification route.</p> <p>This is the info at the address given in the error:</p> <pre><code>(lldb) po 0xee7eb10 (int) $1 = 250080016 &lt;UICollectionViewUpdateItem: 0xee7eb10&gt; index path before update (&lt;NSIndexPath 0x9283a20&gt; 2 indexes [0, 0]) index path after update ((null)) action (delete) </code></pre> <p>Perhaps the index path after update being null is significant...</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload