From 44dbfb0c6af4878814eeb20aa7b5a866bf98e28d Mon Sep 17 00:00:00 2001 From: mhupman Date: Wed, 15 Jan 2014 10:50:28 -0500 Subject: [PATCH 1/2] Fix bugs related to setting MBContactCollectionView.prompt or MBContactCollectionView.showPrompt before a -[UICollectionView reloadData] has been invoked (either explicitly or implicitly). --- MBContactPicker/MBContactCollectionView.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MBContactPicker/MBContactCollectionView.m b/MBContactPicker/MBContactCollectionView.m index 80c8cf6..2a773ac 100644 --- a/MBContactPicker/MBContactCollectionView.m +++ b/MBContactPicker/MBContactCollectionView.m @@ -126,6 +126,16 @@ - (void)setShowPrompt:(BOOL)showPrompt _showPrompt = showPrompt; + // If there aren't any visible cells, then one of the following is true: + // + // 1) -[UICollectionView reloadData] hasn't yet been called. In that case, calling `insertItemsAtIndexPaths:` or + // `deleteItemsAtIndexPaths:` could cause undesired behavior. + // 2) There really aren't any cells. This shouldn't happen since, at a minimum, the entry cell should be present. + if (self.visibleCells.count == 0) + { + return; + } + if (_showPrompt) { [self insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]]]; @@ -140,7 +150,11 @@ - (void)setPrompt:(NSString *)prompt { _prompt = prompt.copy; - if (self.showPrompt) + // If there aren't any visible cells, then one of the following is true: + // + // 1) -[UICollectionView reloadData] hasn't yet been called. In that case, calling `reloadItemsAtIndexPaths:` could cause undesired behavior. + // 2) There really aren't any cells. This shouldn't happen since, at a minimum, the entry cell should be present. + if (self.showPrompt && self.visibleCells.count > 0) { [self reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]]]; } From 1d7423ea83a98a504e1f7c8444e23811d874896a Mon Sep 17 00:00:00 2001 From: mhupman Date: Wed, 15 Jan 2014 10:50:33 -0500 Subject: [PATCH 2/2] whitespace --- MBContactPicker/MBContactCollectionView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MBContactPicker/MBContactCollectionView.m b/MBContactPicker/MBContactCollectionView.m index 2a773ac..2029fa2 100644 --- a/MBContactPicker/MBContactCollectionView.m +++ b/MBContactPicker/MBContactCollectionView.m @@ -396,7 +396,7 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection CGFloat newWidth = MAX(50, [prototype widthForText:self.searchText]); CGSize cellSize = CGSizeMake(MIN([self maxContentWidth], newWidth), self.cellHeight); - + return cellSize; } else