相关疑难解决方法(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
查看次数

UIcollectionView cellForItemAtIndexPath仅在iOS 10中返回Null.适用于iOS 9和iOS 8

我有一个应用程序,愉快地运输了几年.它在UICollectionView中检索RSS源.cellForItemAtIndexPath方法设置文本并调用数据源方法以从源中指定的链接加载图像.如果不存在,则加载网页数据并搜索<img>标签以获取图像.找到/加载图像后,调用委托方法将图像添加到单元格.(下面)

当在iOS 8和9中运行时,一切都很开心,但是当在iOS 10中运行时,可视单元格在最初加载RSS源时用图像更新但滚动时没有添加图像,我从cellForItemAtIndexPath获得NULL.

当我向后滚动时显示图像,如果我向imageWasLoadedForStory添加reloadItemsAtIndexPaths但是reloadItemsAtIndexPaths会破坏性能,则会显示图像.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
           // ...    

          if (story.thumbnail) {
          [imageView setAlpha: 1.0];
          imageView.image = story.thumbnail;
          UIActivityIndicatorView *lActivity = (UIActivityIndicatorView *) [collectionView viewWithTag: 900];
          [lActivity removeFromSuperview];
          }else{
               [story setDelegate: self];
               [story findArticleImageForIndexPath: indexPath];
          }
          //  ...
}



//delegate method.  Called when image has been loaded for cell at specified indexpath

- (void) imageWasLoadedForStory: (RSSStory *) story forIndexPath: (NSIndexPath *) indexPath
{
        //get cell
        CustomCollectionViewCell *customCell = (id) [self.collectionview cellForItemAtIndexPath: indexPath];

        NSLog(@"imageWasLoadedForStory …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewcell ios10 xcode8

3
推荐指数
1
解决办法
3594
查看次数