Reputation: 3545
I try to add a new cell in my UIcollectionView but it doesn't work. In fact I send a post request to my API, I wait for the response, when I get the response, I put de JSON content into an NSDictionnary.
My CellForItemAtIndexPath Datasource method loads cell content from an array called "formationsData", so when I get the response, I add my NSDictionnary into this array.
In numberOfItemAtIndexPath I return something like : [self.formationData count].
Here is my code when I post my request :
NSDictionary * response = [responseJSON valueForKey:@"formation"];
[(NSMutableArray *)_formationsView.carousel.formationsData addObject:response];
[_formationsView.carousel insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem: _lastRowIndex-1 inSection:0]]]; //insert at index : last row - 1
//[_formationsView.carousel reloadData]
Before I was using reloadData but my app crash when I do that.
My problem :
Upvotes: 0
Views: 67
Reputation: 124997
Before I was using reloadData but my app crash when I do that.
Then that's the problem you need to solve. Just adding an item to the array you use to populate the collection view isn't enough to make a cell appear. The collection view doesn't have any idea where the data source gets its data; when there's a change to the data, you need to call -reloadData
or similar.
If -reloadData
causes a crash, then you need to figure out why and fix it.
Upvotes: 1