相关疑难解决方法(0)

在强制滚动后,cellForItemAtIndexPath返回nil以使其可见

所以我试图编写一些代码来将集合视图滚动到某个索引,然后拉入对单元格的引用并执行一些逻辑.但是我注意到如果在滚动之前该单元格当前不可见,则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以便为一个单元格返回一些东西突然出现在它前面的滚动的结果?

objective-c ios uicollectionview ios7

17
推荐指数
3
解决办法
9373
查看次数

标签 统计

ios ×1

ios7 ×1

objective-c ×1

uicollectionview ×1