我有这门课,我将在顶部菜单 View 上工作。
这是代码:
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 项目
我放的 Controller (仅用于测试..通常 View 有自己的文件..)
//
// 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/