【发布时间】:2015-01-21 15:52:11
【问题描述】:
我有一个集合视图,出于某种目的,我想在动态更新单元格后重新调整高度。因此集合视图将显示所有单元格,无需滚动。
我尝试了两种类型的代码,
首先是正常的:
[self.ProjectCollectionView reloadData];
[self.ProjectCollectionView layoutIfNeeded];
NSLog(@"setting contraint to %f from cache", weakself.ProjectCollectionView.contentSize.height);
#endif
self.ProjectCollectionViewHeightConstraint.constant = self.ProjectCollectionView.contentSize.height;
[self.ProjectCollectionView layoutIfNeeded];
然而 contentSize 为 0:
setting contraint to 0.000000 from cache 来自缓存
我尝试了一个 GCD:
[self.ProjectCollectionView reloadData];
__weak typeof(HomeViewController) *weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"setting contraint to %f from cache", weakself.ProjectCollectionView.contentSize.height);
weakself.ProjectCollectionViewHeightConstraint.constant = weakself.ProjectCollectionView.contentSize.height;
[weakself.ProjectCollectionView layoutIfNeeded];
});
这次显示setting contraint to 410.000000 from cache
我一头雾水,第一个代码也应该在主线程上运行,我添加了一个断点并使用线程信息显示:
(lldb) thread info
thread #1: tid = 0x439ee, 0x0000000106c1f411 MCompass`-[HomeViewController fetchUserModelCache](self=0x00007fd258447e50, _cmd=0x0000000106d1dd7b) + 465 at HomeViewController.m:245, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
为什么不一样?
【问题讨论】:
标签: ios