So basically i have search method "searchTableList" and after i get the result i want, i want to reload the uicollectionview
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
// NSLog(@"Text change - %d",isSearching);
//Remove all objects first.
[filteredContentList removeAllObjects];
if([searchText length] != 0) {
isSearching = YES;
[self searchTableList];
}
else {
isSearching = NO;
}
[self.collectionView reloadData];
}
However after "[self.collectionView reloadData]" Nothing happens !
After using this, it crashes all the time !
[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];
[self.collectionView reloadData];
What can i do, Thanks alot!!! :D
Error message is:
2014-04-16 18:24:35.684 SampleProject1[59602:60b] the item width must be less that the width of the UICollectionView minus the section insets left and right values.
2014-04-16 18:24:37.709 SampleProject1[59602:60b] *** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionView.m:3688
2014-04-16 18:24:37.713 SampleProject1[59602:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert item 0 into section 0, but there are only 0 items in section 0 after the update'
Fixed It:
Basically i was returning the count of an unused array which always had a lenght of 0 instead of the relevant array !
So i had to change This:
if (isSearching) {
return [searchResult count];
} else {
return [self.tracks count];
}
To: if (isSearching) {
return [filteredContentList count];
} else {
return [self.tracks count];
}
Then after this i removed all the reloadData jargons and replaced it with:
[self.collectionView reloadData];
Thanks alot guys !!