Ios 如何获取UICollectionView后代中原型单元的大小?

Ios 如何获取UICollectionView后代中原型单元的大小?,ios,uicollectionview,uicollectionviewlayout,Ios,Uicollectionview,Uicollectionviewlayout,我有一个类是UICollectionView的后代。我在用故事板 我怎样才能得到它的原型细胞的大小 我尝试在awakeFromNib中调用dequeueReusableCellWithReuseIdentifier,但在控制台中得到异常:EXC\u BAD\u访问(code=2,address=0xbf7fffdc)) 我需要单元格大小,因为我想在中更改布局 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(U

我有一个类是UICollectionView的后代。我在用故事板

我怎样才能得到它的原型细胞的大小

我尝试在
awakeFromNib
中调用
dequeueReusableCellWithReuseIdentifier
,但在控制台中得到
异常:EXC\u BAD\u访问(code=2,address=0xbf7fffdc))

我需要单元格大小,因为我想在中更改布局

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

您可以这样得到它:

CGFloat height = [[tableView dequeueReusableCellWithIdentifier:reusableIdentifier] bounds].size.height;

但是,如果您在
awakeFromNib
中获得了错误的访问权限,您可能应该从该自定义单元格粘贴一些代码。

您的答案是UITableView,而问题是关于UICollectionView,UICollectionView也是如此。。。不,因为for collection方法是dequeueReusableCellWithIdentifier:forIndexPath,不能在这里使用。它是:dequeueReusableCellWithReuseIdentifier:forIndexPath:-为什么不能使用它?因为在那一点上崩溃了,请使用情节提要案例自己尝试。