Naprawdę, naprawdę chcę dostarczyć "statyczne" komórki do mojego UICollectionView, dawniej z UITableView. Ale wiem, że dobrzy chłopcy i dziewczęta muszą używać dequeueReusableCellWithReuseIdentifier:forIndexPath:
jako fabryki dla naszych komórek. Proponuję następujący schemat i proszę o opinie na temat jego potencjału. Jak na razie to działa dla mnie, ale lękam się nieznanego gnojka.Czy muszę wywoływać funkcję usuwania uniesienia UICollectionView: z poziomu komórkiFoldPath źródła danych :?
#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
}
Rozmyślnie błyszczę nad szczegółami, takimi jak konfigurowanie komórki. Szaleństwo? Geniusz? Tylko status quo? Wydaje się, że działa do tej pory, ale obawiam się, że Apple w jakiś sposób oczekuje, że dequeue
zostanie wywołane z poziomu cellForPath
. jakieś pomysły?
Myślę, że prawdziwą odpowiedzią jest "nie musisz tego robić!" :) – Fattie