简体   繁体   中英

CollectionView with multiple cell templates (use of undeclared type, <typeName> is ambiguous for type lookup in this context)

In one of my collection views I have to use two cell templates for different sections. For both cells I use .xib files. I have two custom classes: OverprintsCollectionViewCell and OverprintsCollectionViewDetailCell .

In the view controller where the said collection view is located in `` I use section index to decide which template to use. The code looks like this:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    if collectionView is OverprintsCollectionView {

        if indexPath.section == 0 {
            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "twoLblCell", for: indexPath) as? OverprintsCollectionViewCell {

                // Swift compiler message in the line above:  "Use of undeclared type 'OverprintsCollectionViewCell'"

                // cell setup  

                return cell
            }
        } else if indexPath.section == 1 {
            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "twoLblDetailCell", for: indexPath) as? OverprintsCollectionViewDetailCell {

                // Swift compiler message in the line above:  "'OverprintsCollectionViewDetailCell' is ambiguous for type lookup in this context"

                // cell setup  

                return cell
            }
        }

    }
    return UICollectionViewCell()
}

App builds and runs successfully despite those errors. I've never used a collection view with more than one cell template before and I'm not really sure what could be causing this problem.

Some of the things I've checked after a little bit of googling: - Both files ( OverprintsCollectionViewCell.swift and OverprintsCollectionViewDetailCell.swift ) have properly set targets

两次检查所有内容(所有标识符,目标等)后,清理项目,重新启动Xcode,实际上是在删除项目的派生数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM