私は実際には、私のUICollectionViewに「静的な」セルを提供したいと思っています。昔、UITableViewを使っていました。しかし私は良い男の子と女の子がdequeueReusableCellWithReuseIdentifier:forIndexPath:
を私たちの細胞のための工場として使わなければならないことを知っています。だから私は以下の計画を提案し、その可能性についてのフィードバックを要求する。これまでのところ、それは私のために働いていますが、私は未知の落とし穴を恐れています。データソースのcellForPath:?内からUICollectionViewのdequeueCell:を呼び出す必要がありますか?
#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がdequeue
をcellForPath
の中から呼び出そうとしていることを恐れています。何かご意見は?
本当の答えは「あなたはそれをする必要はありません」と思います。 :) – Fattie