Ich habe eine CollectionView
Control erstellt und mit Bildern gefüllt. Jetzt möchte ich bei einem bestimmten Index beim Start zu einem Gegenstand blättern. Ich habe scrollToItemAtIndexPath
ausprobiert wie folgt:xcode CollectionViewController scrollToItemAtIndexPath funktioniert nicht
[self.myFullScreenCollectionView scrollToItemAtIndexPath:indexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
Aber ich bin immer folgende Ausnahme. Kann mir jemand sagen, wo ich falsch liege?
2013-02-20 02:32:45.219 ControlViewCollection1[1727:c07] *** Assertion failure in
-[UICollectionViewData layoutAttributesForItemAtIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17
/UICollectionViewData.m:485 2013-02-20 02:32:45.221 ControlViewCollection1[1727:c07] must return a
UICollectionViewLayoutAttributes instance from -layoutAttributesForItemAtIndexPath: for path
<NSIndexPath 0x800abe0> 2 indexes [0, 4]
Vergessen Sie nicht die Positionswerte für vertikales und horizontales Scrollen: http://StackOverflow.com/a/18227362/989896 – Alena
Diese Antwort hat mich so viel Haar-ziehen gerettet, danke! Durch das Verschieben meiner Bildgrößenaktualisierung und das erneute Laden von Code in viewDidLayoutSubviews wurde auch eine lästige Sammlungsansichtswarnung gelöscht, sodass ich doppelt verschuldet bin. – phatmann
Ich habe es in der ViewDidApper anstelle der ViewDidLayoutSubviews, da ich es nur einmal scrollen möchte, nicht jedes Mal, wenn das Layout neu berechnet wird, aber Sie meinen Tag gespeichert. – Vaseltior