【发布时间】:2012-12-04 20:38:12
【问题描述】:
我将 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 无法正常工作 - 重复前 2 组数据...
- (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;
}
正如您所希望看到的 - 每次调用时都会初始化保存信息(潮汐)的数组,并且我已尽可能检查输入的数据是否正确。 如果有任何帮助,我将不胜感激...
【问题讨论】:
-
我不知道这是否会有所帮助 - 基本上第一个“外部”集合视图在 7 天内每天都有一个单元格,嵌入式集合包含 3 或 4 个数据单元格。
-
上面的第二个 cellForItemAtIndexPath 函数为前 2 个外部表调用 - 之后再也不会...
标签: ios uicollectionview uicollectionviewcell