如何在同一个CollectionViewController中使用两个CollectionViewCell?

时间:2018-03-22 12:03:24

标签: ios objective-c xcode

我想在同一- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; // Configure the cell cell.textLabel.text = [NSString stringWithFormat:@"%li", (long)indexPath.row + 1]; return cell; } 中使用两个is_page_template('template-procedure-minimal')

你能帮我吗?

感谢

TRUE

1 个答案:

答案 0 :(得分:0)

为每个单元格类型指定唯一的重用标识符,并在必要时为UICollectionViewCell的自定义子类。在cellForItemAtPath函数中,使用标识符来获取适合路径的标识符,例如

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

    if (indexPath.item % 2 == 0) {
        EvenCollectionViewCell *cell = (EvenCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier: "evenCell" forIndexPath :indexPath];

        // Configure the cell
        ...

        return cell;
    } else {
        OddCollectionViewCell *cell = (OddCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier: "oddCell" forIndexPath: indexPath];

        // Configure the cell
        ...

        return cell;
    }
}