There is a change in behavior in iOS7 where index paths are sometimes instances of NSIndexPath
and other times UIMutableIndexPath
. The problem is that isEqual
between these two classes is always going to return NO
. Thus, you cannot reliably use index paths as dictionary keys or in other scenarios that rely on isEqual
.
I can think of a couple of viable solutions:
Write a method that always returns an instance of
NSIndexPath
and use it to generate keys:- (NSIndexPath *)keyForIndexPath:(NSIndexPath *)indexPath { if ([indexPath class] == [NSIndexPath class]) { return indexPath; } return [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]; }
Identify rows by the data, not the index path. For example, if your data model is an array of
NSString
, use that string as the key into yourselectedIndexes
map. If your data model is an array ofNSManagedObjects
, use theobjectID
, etc.
I'm successfully using both of these solutions in my code.
EDIT Modified solution (1) based on @rob's suggestion of returning NSIndexPaths
rather than NSStrings
.