我正在尝试将视图、单元格内、集合视图内的插座连接到我的视图控制器文件,但我不断收到此错误。
非法配置:HomeViewController 到 UIView 的 runningCard 接口无效。插座不能连接到重复的内容。
我应该怎么办 ?
你必须做这样的事情,希望这会有所帮助。
import UIKit
class CustomCollection: UICollectionViewCell {
@IBOutlet var myView: UIView!
/*
Please note you have to create the outlet yourself and then
drag it to a view that you add to your cell, you cant use your view from your cell.
*/
}
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collection: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5//Number of rows in cell
}
var viewFromCell = [UIView()]//This array of views gets assigned by the collectionview method bellow.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collection.dequeueReusableCell(withReuseIdentifier: "myCell", for: indexPath) as! CustomCollection
cell.myView = viewFromCell[indexPath.row]// This line of code gets the views from each cell and assigns them to the array of views declared above.
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句