我意识到有许多问题已经与粘性标题相关但我找不到符合我特定需求的答案。
我正在构建一个EPG,到目前为止,以下是以传统布局格式完成布局的。
忽略样式,因为到目前为止这个项目还处于起步阶段。实际数据是从本地存储在SQLite数据库中的Web服务中提取的。第一行是存储在NSArray中的时间,每行中的第一项是从不同的URL(来自数据)中提取并存储在NSArray中的图标。每行都是一个部分,每个部分都有动态数量的项目(程序)。每个单元格的框架(X,Y,宽度,高度)基于程序运行的分钟数计算并存储在布局时要引用的字典中。
我的问题是现在我无法弄清楚如何粘贴第一部分(时间轴)和每个部分(图标)中的第一个项目,以便当用户滚动时EPL被推到它们下面。这是我的准备布局方法:
- (void)prepareLayout {
if ([self.collectionView numberOfSections] == 0) {
return;
}
[self calculateFramesForAllPrograms];
NSMutableDictionary *newLayoutInfo = [NSMutableDictionary dictionary];
NSMutableDictionary *cellLayoutInfo = [NSMutableDictionary dictionary];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
NSLog(@"Prepare layout %lu", numOfChannels);
for (NSInteger section = 0; section<numOfChannels+EXTRA_ROW_FOR_TIME; section++) {
if(section==0){
for (NSInteger item = 0; item<=HOURS_IN_A_DAY+EXTRA_ROW_FOR_TIME; item++){
if(item==0){
indexPath = [NSIndexPath indexPathForItem:item inSection:section];
UICollectionViewLayoutAttributes *itemAttributes =
[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
itemAttributes.frame = [self frameForItemAtIndexPath:indexPath];
cellLayoutInfo[indexPath] = itemAttributes;
}else {
indexPath = [NSIndexPath indexPathForItem:item inSection:section];
UICollectionViewLayoutAttributes *itemAttributes =
[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
itemAttributes.frame = [self frameForItemAtIndexPath:indexPath];
cellLayoutInfo[indexPath] = itemAttributes;
}
}
}else{
NSString *query = [NSString stringWithFormat:@"SELECT COUNT(channel_code) AS channels FROM epg WHERE channel_code='%@", self.channelCodes[section-EXTRA_ROW_FOR_TIME]];
NSString *completedQuery = [query stringByAppendingString:@"'"];
//NSLog(@"string %@", completedQuery);
db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];
[db open];
NSUInteger itemCount = [db intForQuery:completedQuery];
for (NSInteger item = 0; item <itemCount+EXTRA_ROW_FOR_TIME; item++) {
if(item==0){
indexPath = [NSIndexPath indexPathForItem:item inSection:section];
UICollectionViewLayoutAttributes *itemAttributes =
[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
itemAttributes.frame = [self frameForItemAtIndexPath:indexPath];
cellLayoutInfo[indexPath] = itemAttributes;
}else {
indexPath = [NSIndexPath indexPathForItem:item inSection:section];
UICollectionViewLayoutAttributes *itemAttributes =
[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
itemAttributes.frame = [self frameForItemAtIndexPath:indexPath];
cellLayoutInfo[indexPath] = itemAttributes;
}
//NSLog(@"ITEM ATTR: %@", itemAttributes);
}
}
}
newLayoutInfo[reuseIdentifier] = cellLayoutInfo;
self.layoutInfo = newLayoutInfo;
//NSLog(@"Layout Info %@", self.layoutInfo);
}
我一直在尝试关注Brightec's tutorial,但到目前为止还没有运气,以适应我的收藏视图。任何帮助将不胜感激。