gpt4 book ai didi

ios - 我需要调用 UICollectionView 的 dequeueCell : from within the data source's cellForPath:?

转载 作者:可可西里 更新时间:2023-11-01 03:49:32 26 4
gpt4 key购买 nike

我真的非常想为我的 UICollectionView 提供“静态”单元格,就像过去使用 UITableView 一样。但我知道我们好 child 必须使用 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
}

我故意掩盖了配置单元格等细节。疯狂?天才?只是现状?到目前为止它似乎工作正常,但我担心,不知何故,Apple 希望从 cellForPath 中调用 dequeue。有什么想法吗?

最佳答案

Apple TSI Guy 的回复:

Although you said your app works, you really should use "dequeueReusableCellWithReuseIdentifier" from within the data source method "cellForItemAtIndexPath". That is the supported use pattern. Don't try to hold on you MyCellClass, let the collection view manage that and it will ask you to dequeue it if necessary.

我要噘嘴了,改一下我的代码,然后发出增强请求。但我告诉你,它工作得很好!

关于ios - 我需要调用 UICollectionView 的 dequeueCell : from within the data source's cellForPath:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15939234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com