我需要知道何时重新加载UICollectionView已经完成以便以后配置单元格(因为我不是单元格的数据源 - 其他明智的就是已经完成它...)
我试过像这样的代码
[self.collectionView reloadData];
[self configure cells]; // BOOM! cells are nil
Run Code Online (Sandbox Code Playgroud)
我也试过用
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:^(BOOL finished) {
// notify that completed and do the configuration now
}];
Run Code Online (Sandbox Code Playgroud)
但是当我重新加载数据时,我正在崩溃.
如何将数据重新加载到集合中,并且只有在完成重新加载后才能重新加载 - 执行特定的完成处理程序
objective-c-blocks completionhandler uicollectionview uicollectionviewcell
正如标题所暗示的那样,我UICollectionView在调用后不会立即更新并显示单元格reloadData.相反,它似乎最终在30-60秒后更新我的集合视图.我的设置如下:
UICollectionView添加到查看故事板控制器与两个delegate和dataSource设置为视图控制器和标准出口设置
numberOfSectionsInRow&cellForItemAtIndexPath都实现并引用原型细胞和imageView在它的内部
以下是转到Twitter的代码,获取时间轴,将其分配给变量,使用推文重新加载表格视图,然后通过推文查找照片并使用这些项目重新加载集合视图.
即使我注释掉显示图像的代码,它仍然不会改变任何东西.
SLRequest *timelineRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:timelineURL parameters:timelineParams];
[timelineRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(responseData) {
JSONDecoder *decoder = [[JSONDecoder alloc] init];
NSArray *timeline = [decoder objectWithData:responseData];
[self setTwitterTableData:timeline];
for(NSDictionary *tweet in [self twitterTableData]) {
if(![tweet valueForKeyPath:@"entities.media"]) { continue; }
for(NSDictionary *photo in [[tweet objectForKey:@"entities"] objectForKey:@"media"]) {
[[self photoStreamArray] addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[photo objectForKey:@"media_url"], @"url",
[NSValue valueWithCGSize:CGSizeMake([[photo valueForKeyPath:@"sizes.large.w"] floatValue], [[photo …Run Code Online (Sandbox Code Playgroud)