我将在顶级菜单视图中上课。
这是代码:
import UIKit
class TopHomeMenuBar: UIView {
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
return cv
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(collectionView)
backgroundColor = UIColor.systemGreen
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
但是,我不断收到错误:
使用未解决的标识符“UICollection”
错误是在以下代码行中突出显示了UICollectionView:
let collectionView: UICollectionView = {
最佳答案
它确实有效
现在仅用XCODE创建了一个简单的SinlgerView项目
我放了Controler(仅用于测试..通常视图有其自己的文件..)
//
// ViewController.swift
//
// Created by ing.conti on 11/06/2020.
// Copyright © 2020 ing.conti. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
class TopHomeMenuBar: UIView {
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
return cv
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(collectionView)
backgroundColor = UIColor.systemGreen
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
关于ios - 在单独的UICollection类中使用未解析的标识符'UICollection',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62321332/