【发布时间】:2014-03-17 04:06:06
【问题描述】:
假设我想实现 Pinterest 的 pin page,像这样:
这是我的方法:
- 创建一个
UICollectionViewController,pin 的页面是UICollectionViewCell - cell 由两个组件组成:pin info child vc &&瀑布 child vc
那么问题来了:如何复用子视图控制器?
一些伪代码:
- (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
}
每次调用这个方法都会创建一个新的子视图控制器,可以吗,或者如何改进?
【问题讨论】:
标签: ios objective-c uicollectionview childviewcontroller