我正在尝试编写一些代码,使集合视图滚动到特定的索引,然后获取对单元格的引用并执行一些逻辑。但是我注意到,如果该单元格在滚动之前不可见,cellForItemAtIndexPath
调用将返回空值,导致我的其余逻辑失败。
[_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]];
当滚动导致某个单元格突然出现时,是否需要调用其他方法以使cellForItemAtIndexPath
返回该单元格的内容?