在UITableView中的滚动Filmstrip中的每个UICollectionViewCell中添加UIButton
首先,让我描述一下迄今为止的情景。 以下是我的UICollectionView在UITableView中的Scrolling Filmstrip样式的工作原理的基本概要:
- 用一个自定义的UITableViewCell创build一个普通的UITableView
- 创build一个将被添加到单元格的contentView的自定义UIView
- 自定义UIView将包含一个UICollectionView
- 自定义UIView将成为UICollectionView的数据源和委托,并pipe理UICollectionView的stream布局
- 使用自定义UICollectionViewCell来处理收集视图数据
- 使用NSNotification通知主控制器的UITableView何时已经select一个集合视图单元并加载详细视图。
到目前为止,我已经能够创build上面描述的那些,但正如你可以在图片中看到的,我也想在每个UICollectionViewCell中添加一个UIButton,这样当我点击UIButton时,它的图像将会变成标记和数据在这个UICollectionViewCell将被保存到一个数组中。 最后,当我点击右上angular的三angular形button,它会推动到另一个视图与arrays,保存选定的数据传递。
这里是我所有的相关课程:
UITableView的
- ViewController.h
- ViewController.m
的UIView
- ContainerCellView.h
- ContainerCellView.m
UICollectionViewCell
- CollectionViewCell.h
- CollectionViewCell.m
的UITableViewCell
- ContainerCell.h
- ContainerCell.m
我的问题是,我不能让我的UIButton至less显示(现在)下面的代码:
ContainerCellView.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath]; NSDictionary *cellData = [self.collectionData objectAtIndex:[indexPath row]]; ... // >>> Select Button <<< UIButton *button = (UIButton *)[cell viewWithTag:200]; [button setFrame:CGRectMake(0, 0, 50, 60)]; [button setTitle:@"Button" forState:UIControlStateNormal]; [cell.contentView addSubview:button]; //??? // >>> End Select Button <<<< ... return cell; }
ContainerCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code _collectionView = [[NSBundle mainBundle] loadNibNamed:@"ContainerCellView" owner:self options:nil][0]; _collectionView.frame = self.bounds; [self.contentView addSubview:_collectionView]; } return self; }
我做错了什么,我该如何做得更好? 如果您需要更多信息,欢迎您提出要求。 提前致谢。
确保(UIButton *)[cell viewWithTag:200]
正在返回你所期望的,一个新的button在这里将符合你的目的。