我将 UICollectionView 嵌入到另一个 UICollectionView 中(作为一种表格)。第一个集合视图工作正常 - 我得到了正确数量的单元格和其中的正确信息。第二个但是我只显示前两组数据。这是外部集合视图的 cellForItemAtIndexPath 的代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Main Tide Data Table Cell";
TideDataTableCell* tideDayDataCell = [self.tideDataTable dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
tidalDate* tideDate = self.tidalDates[indexPath.row];
tideDayDataCell.tides = nil;
tideDayDataCell.tides = [[NSMutableArray alloc] initWithCapacity:0];
tideDayDataCell.tideDataTable.delegate = tideDayDataCell;
tideDayDataCell.tideDataTable.dataSource = tideDayDataCell;
self.tideDataTable.backgroundColor = [UIColor lightGrayColor];
tideDayDataCell.tides = tideDate.tides;
tideDayDataCell.backgroundColor = [UIColor whiteColor];
tideDayDataCell.dayLabel.text = tideDate.dateString;
tideDayDataCell.averageTideHeight = self.avgTideHeight;
return tideDayDataCell;
}
这是内部集合视图的 cellForItemAtIndexPath 无法正常工作 - 重复前两组数据......
- (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.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;
}
如您所见 - 每次调用时都会初始化保存信息(潮汐)的数组,并且我已尽可能检查输入的数据是否正确。我将不胜感激任何帮助...