所以我试图编写一些代码来将集合视图滚动到某个索引,然后拉入对单元格的引用并执行一些逻辑.但是我注意到如果在滚动之前该单元格当前不可见,则cellForItemAtIndexPath调用将返回nil,导致其余逻辑失败.
[_myView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index
inSection:0]
atScrollPosition:UICollectionViewScrollPositionTop
animated:NO];
//Tried with and without this line, thinking maybe this would trigger a redraw
[_myView reloadData];
//returns nil if cell was off-screen before scroll
UICollectionViewCell *cell =
[_myView cellForItemAtIndexPath:
[NSIndexPath indexPathForItem:index inSection:0]];
Run Code Online (Sandbox Code Playgroud)
是否有一些其他的方法我必须调用,cellForItemAtIndexPath以便为一个单元格返回一些东西突然出现在它前面的滚动的结果?