Ios 如何在一个Tableview中加载不同的集合视图单元格样式

Ios 如何在一个Tableview中加载不同的集合视图单元格样式,ios,objective-c,uitableview,uicollectionview,Ios,Objective C,Uitableview,Uicollectionview,其实我想实现下面的设计 在这里,我使用XIB在tableview的每个部分中加载不同的CollectionView。这是我在tableview单元中对Viewcontroller和collectionview单元的设计结构。 我试过一些东西,供你参考 Tableviewcell.m - (void)awakeFromNib { [super awakeFromNib]; // Initialization code [collection registerNib:[UI

其实我想实现下面的设计

在这里,我使用XIB在tableview的每个部分中加载不同的CollectionView。这是我在tableview单元中对Viewcontroller和collectionview单元的设计结构。

我试过一些东西,供你参考

Tableviewcell.m

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [collection registerNib:[UINib nibWithNibName:@"ScheduleCell" bundle:nil] forCellWithReuseIdentifier:@"cellid"];
    [collection registerNib:[UINib nibWithNibName:@"ResultCell" bundle:nil] forCellWithReuseIdentifier:@"cellno"];
    [collection registerNib:[UINib nibWithNibName:@"ResultCell1" bundle:nil] forCellWithReuseIdentifier:@"cellno1"];
    [collection registerNib:[UINib nibWithNibName:@"ResultCell2" bundle:nil] forCellWithReuseIdentifier:@"cellno2"];
    [collection registerNib:[UINib nibWithNibName:@"ResultCell3" bundle:nil] forCellWithReuseIdentifier:@"cellno3"];



}

-(void)configureCell:(id <UICollectionViewDelegate,UICollectionViewDataSource>)delegate andIndex:(NSIndexPath *)indexPath andTitile:(NSString *)title{
    collection.dataSource = delegate;
    collection.delegate = delegate;
    collection.tag = indexPath.section;

    NSLog(@"collectionArray %ld",(long)collection.tag);

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.collection reloadData];
    });


}
所有都已调用,但我无法从相应的委托获取collectionview.tag。因此,我无法在此处加载不同的collectionview单元格。如果我错了,任何人都会指引我正确的方向

欢迎您在swift或Objective-c中提出建议

我在加载不同的单元格时遇到问题。这里collectionView.tag始终为零。在
configurecell
方法中分配标记时,它不分配。因为没有分配
集合
内存。我无法加载不同的单元格

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* ColCell;

    if (collectionView.tag == 1) {

        ScheduleCell* cell = (ScheduleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
        cell.eventNamelbl.text = @"ScheduleCell";
        ColCell = cell;
    }
    else if (collectionView.tag == 2){

        ResultCell* cell = (ResultCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }
    else if (collectionView.tag == 3){

        ResultCell1* cell = (ResultCell1 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno1" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;
    }
    else if (collectionView.tag == 4){

        ResultCell2* cell = (ResultCell2 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno2" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }
    else if (collectionView.tag == 5){

        ResultCell3* cell = (ResultCell3 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno3" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }


    return  ColCell;
}

在TableCell内定义CollectionView委托,并按您希望的方式格式化数据,然后将数据传递给每个TableCell以显示CollectionView单元格,以便捕获操作,您可以使用协议。tableview代码在哪里?不要调用
[TableCell配置单元格:self and索引:indexPath and Titile:@“事件”]中的code>将显示
,在
cellForRow中调用它
委托方法。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* ColCell;

    if (collectionView.tag == 1) {

        ScheduleCell* cell = (ScheduleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
        cell.eventNamelbl.text = @"ScheduleCell";
        ColCell = cell;
    }
    else if (collectionView.tag == 2){

        ResultCell* cell = (ResultCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }
    else if (collectionView.tag == 3){

        ResultCell1* cell = (ResultCell1 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno1" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;
    }
    else if (collectionView.tag == 4){

        ResultCell2* cell = (ResultCell2 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno2" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }
    else if (collectionView.tag == 5){

        ResultCell3* cell = (ResultCell3 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno3" forIndexPath:indexPath];
        cell.resultlbl.text = @"ResultCell";
        ColCell = cell;

    }


    return  ColCell;
}