Mam UICollectionViewController
:Wybierz elementy programowo w UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
return [self.pageTastes count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CellTasteCollectionView *cell =
[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell"
forIndexPath:indexPath];
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
[[cell imageView] setImage:taste.image];
[cell setObjectId:taste.objectId];
return cell;
}
To działa. Mam to w viewDidLoad
, pozwalając użytkownikowi wybrać kilka pozycji:
[self.collectionView setAllowsMultipleSelection:YES];
Co chcę mieć, jest to, że po raz pierwszy ładuje CollectionView, niektóre elementy się wybrany programowo, w oparciu o ich objectId
w CellTasteCollectionView
.
Oto jak to robię:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
printf("%s\n", [taste.objectId UTF8String]);
}
Nazywa się, gdy użytkownik kliknie na przedmiocie - to nie jest to, co chcę: Chcę element, który ma zostać wybrany automatycznie, gdy UICollectionView
ładunki.
Jak to zrobić?
Dzięki za pomoc. :) – Ali
Należy pamiętać, że wywołanie tej metody programowo nie uruchomi metody collectionView: didSelectItemAtIndexPath :. – Boon