【问题标题】:The myLabel outlet from the UICollectionView to the UILabel is invalid. Outlets cannot be connected to repeating content从 UICollectionView 到 UILabel 的 myLabel 出口无效。插座无法连接到重复内容
【发布时间】:2020-07-03 02:48:50
【问题描述】:

我编写了我的第一个 CollectionView,但构建失败并显示以下错误消息:

“非法配置:从UICollectionView到UILabel的myLabel outlet无效。Outlets无法连接重复内容。”

我在 StackOverflow 上阅读了其他问题,但出现了同样的错误,解决方案是将 UILabel 的内容设置为原型单元格中的内容,并从静态到动态设置“CollectionViewCell.swift”的出口。我不能尝试这个,因为这个选项没有出现。我认为它已经随着新版本的 Xcode 消失了。

我在“CollectionViewCell.swift”中的代码:

import UIKit

class CollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var myLabel: UILabel!
}

我在“ViewController.swift”中的代码:


class LibraryViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

    @IBOutlet weak var sortCollectionView: UICollectionView!

    func numberOfSections(in sortCollectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(_ sortCollectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }

    func collectionView(_ sortCollectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let sortCell = sortCollectionView.dequeueReusableCell(withReuseIdentifier: "sortCell", for: indexPath) as! CollectionViewCell
        sortCell.myLabel.text = "hi"
        return sortCell
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

感谢您的每一个有用的回答:'D

【问题讨论】:

    标签: ios swift xcode uicollectionview


    【解决方案1】:

    好的,我自己修好了! 对于寻找解决方案的每个人: 仔细检查除了 CollectionViewCell 之外是否没有其他 Outlets! 在我的情况下,标签有一个出口到另一件事:^)

    【讨论】:

    • 太好了,(Y)。
    【解决方案2】:

    从 Storyboard 中选择您的 UILabel 并检查它的连接,它可能是旧连接。删除旧连接,您就可以开始了。

    【讨论】:

      猜你喜欢
      • 2021-04-08
      • 2021-03-15
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 2015-10-11
      • 2015-01-24
      相关资源
      最近更新 更多