6

I have developed an RSS reader application using collection views. My problem is, on the very first launch, the app comes up blank.

The process is, the RSS feed is pulled from the web, stored to a temporary file on the device and then displayed via collection views.

My question is How Do i get the app to reload the data automatically once the files have been loaded? So that the user does not see an initial blank screen.

I have tried adding this code

       [self.collection1 performBatchUpdates:^{
       [self.collection1 reloadSections:[NSIndexSet indexSetWithIndex:0]];
   } completion:nil];

However it does not work for the initial view.

Should I do something from the appdelegate? or from the collection view controller itself?

Please advise

Below is the code used to get and display my data....

#pragma mark - UICollectionViewDataSourceDelegate
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  {
  return 1;
  }

- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
 return [_articleListmain count];
}

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
 MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"articleCellmain"
                                                                           forIndexPath:indexPath];
NSDictionary *item = [_articleListmain objectAtIndex:indexPath.item];

// set the article image
[cell.image setImageWithURL:[item objectForKey:@"image"]];

// set the text of title UILabel
cell.title.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"title"]];
cell.title.textColor = [UIColor colorWithRed:33.0f/255.0f green:74.0f/255.0f blue:146.0f/255.0f alpha:1.0f];

// set the text of summary UILabel
cell.description.text = [NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n", [item objectForKey:@"description"]];


cell.targetURL.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"link"]];

cell.category.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"category"]];

cell.date.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"pubDate"]];

cell.image.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"placement.png"]];


return cell;


}
Robert Farr
  • 680
  • 2
  • 7
  • 19

4 Answers4

9

You should be able to use [collectionView reloadData] once you know the download has completed.

RegularExpression
  • 3,531
  • 2
  • 25
  • 36
  • so do i use that in the collection view controller or after i've finished parsing the data. Thats the problem I'm having. – Robert Farr Sep 24 '13 at 00:52
  • Tried that in my collection view and the log shows that it reloads but does not display change the blank display – Robert Farr Sep 24 '13 at 01:06
  • Without seeing the code, I really don't know what would cause this other than the data not being present at the time of the reload. In your cellForItemAtIndexPath, have you inspected your data source (whatever it may be) to see that your data is there? Perhaps you would want to modify your post to include the code for that method. – RegularExpression Sep 24 '13 at 02:44
  • The code has been updated. This data is taken from the web. Parsed, Stored to a Local File using the NSDictionary then displayed. with the CollectionView – Robert Farr Sep 24 '13 at 16:52
4

try this

 [self.collection1 performBatchUpdates:^{
   [collectionView reloadData]
 } completion:nil];

once your download has completed.

Bhushan Rana
  • 149
  • 5
1
[self.collection1 performBatchUpdates:^{
[self.collection1 reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];

Try to replace this code with below code

[self.collection1 performBatchUpdates:^{
[self.collection1 reloadData];
} completion:nil];
Hemant Singh Rathore
  • 2,153
  • 1
  • 24
  • 38
1

I think you just put [self.collection1 reloadData] in the viewWillAppear of the ViewController where your collection view is placed.

OR

You can reloadData it somewhere even before the view appears, like immediately after parsing just make sure you have initialized the view where the collection view is located before reloading.

jyce1492
  • 199
  • 2
  • 15