【发布时间】: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