【问题标题】:Call a function on the first cell in a UICollectionView when it has finished loading完成加载后,在 UICollectionView 中的第一个单元格上调用函数
【发布时间】:2017-02-02 03:40:27
【问题描述】:

我正在创建一个具有全屏水平滚动图像UICollectionView 的 Objective-C iOS 应用程序。

UICollectionView 完成加载其内容时,如何创建在UICollectionView 中的第一个单元格上调用的函数?

【问题讨论】:

  • 如果您下载图像然后在完成块做你的事情很简单。或者,如果您正在加载本地图像,那么在加载图像后立即调用您的函数

标签: ios objective-c view uicollectionview uicollectionviewcell


【解决方案1】:

试试这个

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
if (indexPath.row == 0) {
    callFunction()
}
return cell;
}

或者如果您正在下载图像,您可以在完成块中调用该函数

【讨论】:

    【解决方案2】:

    我想你想滚动到第一项,你可以打电话给scrollToItemAtIndexPath

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    
    [self.collectionView scrollToItemAtIndexPath:indexPath
                                atScrollPosition:UICollectionViewScrollPositionLeft
                                        animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      相关资源
      最近更新 更多