QED*_*QED 6 ios uicollectionview
我真的,真的想为我的UICollectionView提供'静态'单元格,以及UITableView的旧时代.但我知道我们好男孩和女孩必须dequeueReusableCellWithReuseIdentifier:forIndexPath:用作我们细胞的工厂.所以我建议采用以下方案,并就其潜力提出反馈意见.到目前为止,它对我有用,但我害怕一个未知的陷阱.
#import "MyCellClass.h"
@implementation MyViewController {
MyCellClass *_cell0; // etc - many are possible. could store in array
}
-(void)viewDidLoad {
// assume MyCellClass has a +nib and +reuseId. The reader understands.
[_collectionView registerNib:[MyCellClass nib] forCellWithReuseIdentifier:[MyCellClass reuseId]];
}
-(void)viewDidAppear:animated {
// this is where the fun begins. assume proper counts coming from the datasource
NSIndexPath *indexPath = [NSIndexPath indexPathWithRow:0 inSection:0];
_cell0 = [[self collectionView] dequeueReusableCellWithReuseIdentifier:[MyCellClass reuseId] forIndexPath:indexPath];
// etc
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == 0) return _cell0;
// etc
}
Run Code Online (Sandbox Code Playgroud)
我故意掩盖了配置单元格等细节.疯狂?天才?只是现状?它似乎到目前为止工作,但我担心,不知何故,Apple希望dequeue从内部调用cellForPath.有什么想法吗?
Apple TSI 专家的回应:
尽管您说您的应用程序可以工作,但您确实应该在数据源方法“cellForItemAtIndexPath”中使用“dequeueReusableCellWithReuseIdentifier”。这是受支持的使用模式。不要试图保留 MyCellClass,让集合视图来管理它,必要时它会要求您将其出列。
我会撅起嘴,更改我的代码,然后发出增强请求。但我告诉你,效果很好!
| 归档时间: |
|
| 查看次数: |
9297 次 |
| 最近记录: |