我已经使用集合视图开发了一个 RSS 阅读器应用程序。我的问题是,在第一次启动时,该应用程序出现空白。
该过程是,RSS 提要从网络中提取,存储到设备上的临时文件中,然后通过集合视图显示。
我的问题是如何让应用程序在文件加载后自动重新加载数据?这样用户就不会看到初始的空白屏幕。
我尝试添加此代码
[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;
}