假设我想实现 Pinterest 的 pin 页面,像这样:
这是我的方法:
- 制作一个
UICollectionViewController
,pin的页面是一个UICollectionViewCell
- cell 由两个部分组成:pin info child vc && waterfall child vc
然后问题来了:如何重用 subview Controller ?
一些伪代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Pin *pin = self.dataSource[indexPath.row];
// i have to create a new childVC, based on different indexPath.
UITableViewController *pinInfoViewController = [[pinInfoViewController alloc] initWithPin:pin];
[cell updatePinViewWithPin:pin];
[self addChildViewController:pinInfoViewController];
// Add waterfall view controller
}
每次调用这个方法都会创建一个新的child view controller,可以吗,或者如何改进?
最佳答案
我最近遇到过类似的情况,并且在各种解决方案之间做出选择,如 UIViewController within UICollectionView 中详述的那样。 .现在似乎有一个封装此模式的开源项目可用:https://github.com/zats/Voltron .如果您的问题可能通过拥有 UIViewControllers 的 UICollectionView 得到最好的解决,那么它比尝试自己动手更容易完成。
关于ios - UICollectionViewCell 中的 subview Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22446768/