ios - 从 ViewController 到 UILabel 的 currencyLabel 出口无效。插座无法连接到重复内容
问题描述
我将标签插入到 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
您的currencyLabelCurrencyCollectionViewCell
,并像使用它一样使用它
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
}
推荐阅读
- electron - Electron 框架 - 电子从哪里下载新的更新
- python - 如何使用 Chrome 和 Python 拦截服务器客户端请求?
- android - 使用 ListView 传递 ViewPager
- go - func类型的类型转换
- php - Woocommerce:付款完成后更改订单ID
- git - git-remote-https 无法分叉加载到不同地址的 msys-unistring-2.dll
- javascript - 在asp.net mvc中使用jquery从html文本框加载HTML gridview
- javascript - 如何编写从 jsfiddle 到本地主机的日历
- ruby-on-rails - Rails 不断询问我“请在尝试启动应用程序之前运行 `bundle install`”
- python - Python将txt文件转换为列表-优化