关于模型- View - Controller (MVC) 的一个非常基本的问题。
我有一个自定义 UICollectionView,其中填充了自定义 UICollectionViewCells
。 Collection View 在 UICollectionViewDelegateFlowLayout
方法 collectionView: sizeForItemAtIndexPath
中定义单元格的大小。同时,通过自定义集合单元格 View Controller 添加和删除 subview 。
我的问题:在单元格的 View Controller 中添加或删除 subview 时,如何同时告诉 Collection View Controller 更改高度?
我确实理解委托(delegate)和数据源的概念,但认为单元格是它自己的委托(delegate),那么当 subview 时,消息('将高度更改为...')如何从单元格传递到 Collection View Controller 添加/删除?
最佳答案
你试过通知中心吗,
[[NSNotificationCenter defaultCenter] postNotificationName:@"AddedSubViewToCell" object:self];
在 Collection View Controller 的 viewDidLoad 中,
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addedSubViewToCell:) name:@"AddedSubViewToCell" object:nil];
然后实现选择器
- (void)addedSubViewToCell:(NSNotification:)notificationObject
{
//change frame of collection view
//don't forget to remove observer
}
有关 NSNotificationCenter
的详细说明,请参阅 Tutorial
希望这对您有所帮助。 谢谢
关于ios - UICollectionView:从自定义单元格中更改 sizeForItemAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28109466/