如何解决从 ViewController 到 UILabel 的货币标签出口无效插座不能连接到重复的内容
我将 Label 插入到 CollectionView 单元格中,但是当我输出时出现此错误。
错误:从ViewController 到UILabel 的currencyLabel 出口无效。插座不能连接到重复的内容
class ViewController: UIViewController {
var currency = Currency.getCurrency()
@IBOutlet var currencyLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
return currency.count
}
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "currencyCell",for: indexPath) as! CurrencyCollectionViewCell
let currencyList = currency[indexPath.row]
currencyLabel.text = "\(currencyList.currency) \n \(currencyList.cash)"
return cell
}
}
解决方法
您需要在 IBOutlet
类中创建您的 currencyLabel 的 CurrencyCollectionViewCell
,并像使用它一样
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "currencyCell",for: indexPath) as! CurrencyCollectionViewCell
let currencyList = currency[indexPath.row]
cell.currencyLabel.text = "\(currencyList.currency) \n \(currencyList.cash)"
return cell
}
,
你犯了一个简单的错误。
您应该在 CollectionViewCell 中创建下面的插座,而不是在您的 ViewController 中。
@IBOutlet var currencyLabel: UILabel!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。