ios – 如何自动重新加载集合视图?

我使用集合视图开发了一个RSS阅读器应用程序.我的问题是,在第一次启动时,应用程序出现空白.

过程是,RSS提要从Web中提取,存储到设备上的临时文件中,然后通过集合视图显示.

我的问题是如何在文件加载后让应用程序自动重新加载数据?这样用户就看不到初始的空白屏幕.

我试过添加这段代码

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

但是它不适用于初始视图.

我应该从appdelegate做些什么吗?或者从集合视图控制器本身?

请指教

下面是用于获取显示我的数据的代码….

#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;


}

解决方法

一旦知道下载已完成,您应该能够使用[collectionView reloadData].

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...