我使用集合视图开发了一个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].