Ios 当启动多个UITableViewCell时,如何停止UICollectionView中超出边界的UITableViewCell?

Ios 当启动多个UITableViewCell时,如何停止UICollectionView中超出边界的UITableViewCell?,ios,uitableview,uicollectionview,Ios,Uitableview,Uicollectionview,我有一个UITableView,它可以扩展每个单元格的高度,并在选中单元格时显示一个UICollectionView。但是,当我一个接一个地选择一个tableCell并展开它们时,它会毫无错误地完成上述所有操作。 当UICollectionView中填充了单元格,并且每个单元格都有不同数量的项目时(因此James有3个洞察,Tim有4个洞察),当我用较少的项目展开TableViewCell,然后尝试滚动Tim的UICollectionView时,它超出了界限。这是因为当我启动一个新的集合视图时,

我有一个
UITableView
,它可以扩展每个单元格的高度,并在选中单元格时显示一个
UICollectionView
。但是,当我一个接一个地选择一个tableCell并展开它们时,它会毫无错误地完成上述所有操作。 当
UICollectionView
中填充了单元格,并且每个单元格都有不同数量的项目时(因此James有3个洞察,Tim有4个洞察),当我用较少的项目展开TableViewCell,然后尝试滚动Tim的
UICollectionView
时,它超出了界限。这是因为当我启动一个新的集合视图时,它们都采用最近创建的
UICollectionView
numberofitemsin部分:
。我希望创建的视图能够维护最初创建时的
numberOfItemsInSection:
视图,而不是所有
UICollectionView
都采用了最新的
numberOfItemsInSection:
。我希望这是有意义的,但为了更好地理解我的意思,我将粘贴我的代码,下面是来自UITableViewController的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
leaderboardCell *leaderCell = (leaderboardCell *) [self.tableView cellForRowAtIndexPath:indexPath];
isSelected = ![self cellIsSelected:indexPath];
    if ([self cellIsSelected:indexPath]) {
        [leaderCell.collectionView removeFromSuperview];
        leaderCell.collectionView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PostCellInformation" object:nil];
    } else {
if (isSelected) {
            leaderCell.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(320, 65, 322, 200) collectionViewLayout:leaderCell.flowLayout];
            [leaderCell.collectionView registerClass:[userCell class] forCellWithReuseIdentifier:@"userCellID"];
            leaderCell.flowLayout = [[UICollectionViewFlowLayout alloc] init];
            [leaderCell.flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
            UIColor *collectionViewColour = [UIColor colorWithRed:0.17 green:0.28 blue:0.40 alpha:1.0];
            UIColor *borderColour = [UIColor colorWithRed:0.37 green:0.48 blue:0.60 alpha:1.0];
            [leaderCell.collectionView setBackgroundColor:collectionViewColour];
            [leaderCell.collectionView.layer setBorderColor:[borderColour CGColor]];
            [leaderCell.collectionView.layer setBorderWidth:1.0];
            [leaderCell.collectionView setDataSource:leaderCell];
            [leaderCell.collectionView setDelegate:leaderCell];
            }
 }
// Store cell 'selected' state keyed on indexPath
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
    [selectedIndexes setObject:selectedIndex forKey:indexPath];

    [self.tableView beginUpdates];
    [self.tableView endUpdates];
leaderCell
是包含
UICollectionView
UITableViewCell
。我希望每个
UICollectionView
numberofitemsinssection:
应用于每个
UICollectionView,而不是全部。有没有人遇到过类似的问题?提前谢谢

编辑我得出的结论是,要成功实现我在这里想要的目标,我需要解决的是将数据源分配给正确的对象,但是,我不确定我需要将其分配给什么。。。我基本上需要数据源分别处理每个单元格。目前,我的数据源被设置为TableViewCell,这应该是正确的,因为它被分配给每个单独的单元格