How can I automatically download a collection?

I developed an RSS reader using collections. My problem is that when I first start the application becomes empty.

The process is that the RSS feed is pulled from the Internet, stored in a temporary file on the device, and then displayed through the collection.

My question is: How do I get an application to reload data automatically after downloading files? So the user does not see the initial blank screen.

I tried to add this code

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

However, this does not work for the initial presentation.

Do I have to do something from appdelegate? or from the collection view controller itself?

Please inform

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; } 
+6
source share
4 answers

You should be able to use [collectionView reloadData] as soon as you know that the download is complete.

+8
source

try

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

after the download is complete.

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

Try replacing this code with below code

 [self.collection1 performBatchUpdates:^{ [self.collection1 reloadData]; } completion:nil]; 
+1
source

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

OR

You can reload it somewhere else before the view appears, for example, immediately after parsing, just make sure that you initialize the view in which the collection view is located before rebooting.

0
source

Source: https://habr.com/ru/post/954461/


All Articles