Merge pull request #1842 from stewa/empty-collectionview-keyboard-navigation-problem

Fixed: using keyboard navigation in empty CPCollectionView threw exception

Previously, if an empty CPCollectionView was first responder and keyboard navigation was used, a CPInvalidArgumentException (Range {-1, 1} is out of bounds) was thrown.

This commit checks for an empty collection, eliminating the exception.
This commit is contained in:
aparajita
2013-03-12 07:01:53 -07:00
+6 -1
View File
@@ -1210,7 +1210,12 @@ Not supported. Use -collectionView:dataForItemsAtIndexes:fortype:
- (void)_modifySelectionWithNewIndex:(int)anIndex direction:(int)aDirection expand:(BOOL)shouldExpand
{
anIndex = MIN(MAX(anIndex, 0), [[self items] count] - 1);
var count = [[self items] count];
if (count === 0)
return;
anIndex = MIN(MAX(anIndex, 0), count - 1);
if (_allowsMultipleSelection && shouldExpand)
{