完成加载后,在UICollectionView中的第一个单元格上调用一个函数

时间:2017-02-02 03:40:28

标签: ios objective-c view uicollectionview uicollectionviewcell

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

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

2 个答案:

答案 0 :(得分:0)

试试这个

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

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

答案 1 :(得分:0)

我想你想滚动到第一项,你可以拨打scrollToItemAtIndexPath

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.collectionView scrollToItemAtIndexPath:indexPath
                            atScrollPosition:UICollectionViewScrollPositionLeft
                                    animated:YES];