3

I've found a wierd bug for my app on iOS6.

I am using a Collection view to represent a "tree structure" for my app. Each cell has a tableview inside it, and when I select a cell in the table view, i push a new collection view cell with another tableview.

When selecting a tableview cell in the "root of the tree", i need to purge the other collection view cells, and display the new one. I am doing this like this:

for(id e in oldData)
{
    if(i < indexPath.row)
    {
        [newData addObject:e];
    }
    else
    {
        [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:indexPath.section]];
    }
    i++;
}
self.tree = newData;

[self.collectionView deleteItemsAtIndexPaths:indexPaths];

This works splendid in iOS7. However, in iOS6 i sometimes get this exception:

'NSInvalidArgumentException', reason: '-[UICollectionViewUpdateItem action]: unrecognized selector sent to instance 0xa3eedd0'

This exceptions occur on the row

[self.collectionView deleteItemsAtIndexPaths:indexPaths];

I've found some threads about this particular problem, but it seems to be related to a keyboard appearance on iOS6.

How to find a workaround for this bug on iOS6?

Thanks.

Edit:

I think the cause of the problem is this. Check my new question: Subclassing UICollectionViewFlowLayout sometimes crashes on iOS6

Community
  • 1
  • 1
ullstrm
  • 9,812
  • 7
  • 52
  • 83

3 Answers3

2

With reference to Docs Please make sure following things:

  1. indexPaths parameter must not be nil. (Also you should check that indexPaths are not having any indexes that don't exist in your current collection view)
  2. You have updated the datasource prior to calling this method.

e.g.

[indexPaths removeAllObjects];
for(id e in oldData)
    {
    if(i < indexPath.row)
    {
        [newData addObject:e];
    }
    else
    {
        [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:indexPath.section]];
    }
    i++;
}
self.tree = newData;
if([indexPaths count])
    [self.collectionView deleteItemsAtIndexPaths:indexPaths];

Hope this helps.

Himanshu A Jadav
  • 2,286
  • 22
  • 34
1

I met similar issue before.

I resigned the keyboard before calling the deleteItem method.

[[UIApplication sharedApplication].keyWindow findAndResignFirstResponder];

Hopes it is helpful.

Steven Jiang
  • 1,006
  • 9
  • 21
-1

Dismissing the keyboard reliably is done like this:

[self.view endEditing:YES];

Also, you might have update issues, use:

[tableView beginUpdates];
// make changes
[tableView endUpdates];

And always be on the Main thread when updating UIKit views.

Worst case, imeplement action so the cell does respond to selector [UICollectionViewUpdateItem action]:

-(SEL) action{
    // break here to find thread that is calling me!
    return nil;
}
benzoid
  • 56
  • 1
  • 6