A
A
agee2014-06-10 21:05:05
Objective-C
agee, 2014-06-10 21:05:05

Issue with touchesEnded override for UICollectionViewCell subclass?

My UICollectionViewCell subclass has a Boolean editingMode property. It is needed so that, among other things, in this "mode" the didSelectItemAtIndexPath event for the UICollectionView delegate does not fire. I override touchesEnded for this subclass like this:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!_editingMode) {
        [super touchesEnded:touches withEvent:event];
    }
    else {
        // My custom behavior
    }
}

As long as I don't enable editingMode everything goes fine and calling touchesEnded on super produces the expected result: didSelectItemAtIndexPath is called.
Then I do the following:
1. Set editingMode = YES.
2. I click on the cell.
3. I set editingMode = NO back.
4. Again I click on the cell.
After these actions, despite the fact that touch events are intercepted and touchesEnded for super is called, didSelectItemAtIndexPath no longer works.
Funny how the exact same code for a UITableViewCell subclass works as expected.
What do you think could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
agee, 2014-06-11
@agee

Problem solved.
I rewrote touchesEnded like this:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    if (_editingMode) {
        // Do my thing
    }
}

And I have already implemented ignoring the default behavior in editingMode in didSelectItemAtIndexPath:
GDCollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    if (cell.editingMode)
        return; // Do nothing in editing mode

Perhaps this should have been done from the very beginning.

A
An, 2014-06-11
@Flanker_4

That's just the restriction on the selection had to be done in
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question