微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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].

原文地址:https://www.jb51.cc/iOS/331201.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐