小编reb*_*a87的帖子

为什么收集可重用视图未显示?

我想用标题创建UICollectionView.我在mainStoryBoard上设置了Collection Reusable View,但是设备上没有显示任何内容.我试图搜索,但无法找出它为什么没有出现.一世

主要故事板

在此输入图像描述

在设备上

在此输入图像描述

导入UIKit

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {


    @IBOutlet weak var collectionView: UICollectionView!

    var images = ["medal1","medal2","medal3","medal4","medal5","medal6","medal7","medal8","medal9","medal10","medal1","medal2","medal3","medal14"]

    var texts = ["hi","yes","hoo","such","hi","yes","hoo","such","hi","yes","hoo","such","hi","yes"]

    override func viewDidLoad() {
        super.viewDidLoad()



        collectionView.delegate = self
        collectionView.dataSource = self

    }

    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return images.count
    }

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

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell

        cell.myImage.image = UIImage(named: images[indexPath.row])

        cell.achievementLabel.text = texts[indexPath.row]

        return cell …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionreusableview swift

2
推荐指数
1
解决办法
3041
查看次数