Issue with nested UICollectionViews

拟墨画扇 提交于 2019-12-08 02:34:09

问题


I have 2 nested UICollectionViews. The delegate for the outer collection view is the main view controller, and the inner collection views delegate is the UICollectionCell of the outer collection view.

The outer collection view has only a label and the inner collection view in it - normally there would be seven of these, the inner collection view should contain 3 or 4 cells (containing 3 labels).

The problem is that the inner collection view only seems to get updated twice (for the first 2 sets of data in the outer views) after that they repeat.

Here is the cellForItemAtIndexPath for the outer UICollectionView

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Main Tide Data Table Cell";

    TideDataTableCell* tideDayDataCell = [self.tideDataTable dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    tideDayDataCell.tideDataTable.delegate = tideDayDataCell;
    tideDayDataCell.tideDataTable.dataSource = tideDayDataCell;
    tidalDate* tideDate = self.tidalDates[indexPath.row];
    tideDayDataCell.thisTidalDate = tideDate;
    tideDayDataCell.dayLabel.text = tideDate.dateString;
    tideDayDataCell.averageTideHeight = self.avgTideHeight;

    tideDayDataCell.backgroundColor = [UIColor whiteColor];
    self.tideDataTable.backgroundColor = [UIColor lightGrayColor];
    return tideDayDataCell;
}

... and here is the cellForItemAtIndexPath for the second UICollectionView which is in the UICollectionViewCell object for the out UICollection view!

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* CellIdentifier = @"Tide Info Table Cell";

    TidalTideTableCell* tidalTideTableCell = [self.tideDataTable dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    tidalTideTableCell.timeTideLabel.text = @"";
    tidalTideTableCell.heightTideLabel.text = @"";
    tidalTideTableCell.hwlwTideLabel.text = @"";
    self.tideDataTable.backgroundColor = [UIColor clearColor];
    Tide* tide = self.thisTidalDate.tides[indexPath.row];
    tidalTideTableCell.heightTideLabel.text = [[NSNumber numberWithDouble:tide.height] stringValue];
    if (tide.height > self.averageTideHeight)
    {
        tidalTideTableCell.hwlwTideLabel.text = @"HW";
    }
    else
    {
        tidalTideTableCell.hwlwTideLabel.text = @"LW";
    }
    tidalTideTableCell.timeTideLabel.text = tide.date;
    tidalTideTableCell.backgroundColor = [UIColor clearColor];
    return tidalTideTableCell;
}

I hope this makes sense - please ask if it's not... I just don't understand why it's ok for the first 1 sets of data and then not for the next 5...


回答1:


This was resolved by calling [UICollectionView refreshdata] in the dequeue method for the mother (outer) UICollectionView



来源:https://stackoverflow.com/questions/13741706/issue-with-nested-uicollectionviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!