在滚动幻灯片中添加的UIButton每个UICollectionViewCell内的UITableV

2019-10-24 11:27发布

首先,让我描述到目前为止,我已经得到了该方案。 下面是我在滚动幻灯片风格UICollectionView内的UITableView如何工作的基本概要:

  • 创建一个自定义的一个正常的UITableView 的UITableViewCell
  • 创建将被添加到该单元的内容查看自定义的UIView
  • 自定义的UIView将包含UICollectionView
  • 自定义的UIView将成为数据源和委托的UICollectionView和管理UICollectionView的流布局
  • 使用自定义UICollectionViewCell处理集合视图数据
  • 使用NSNotification当已经选择的集合视图小区通知主控制器的的UITableView并加载详图。

到目前为止,我已经能够创造上述那些,但你可以在图片中看到我还想添加一个UIButton的每个UICollectionViewCell这样,当我挖掘的UIButton它的形象会变成检查标记,并在数据UICollectionViewCell将被保存到数组中。 在结束时,当我点击右上角三角按钮它会推到另一个视图与保存选择的数据通过在阵列。

我这里还有所有的,我已经得到了相关的类:

UITableView的

  • ViewController.h
  • ViewController.m

的UIView

  • ContainerCellView.h
  • ContainerCellView.m

UICollectionViewCell

  • CollectionViewCell.h
  • CollectionViewCell.m

的UITableViewCell

  • ContainerCell.h
  • ContainerCell.m

我的问题是,我不能与此下面的代码让我的UIButton至少露面(现在):

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;
}

我做了什么错了,我应该怎么做更好? 如果您需要更多的信息,你比欢迎更多的要求。 提前致谢。

Answer 1:

确保(UIButton *)[cell viewWithTag:200]将返回你所期望的,在这里一个新的按钮将成为你的目的。



文章来源: Adding UIButton in each UICollectionViewCell in Scrolling Filmstrip within UITableView