【发布时间】:2021-12-02 13:26:50
【问题描述】:
我是 swift 的新手。我在侧 tableView 中有 CollectionView。我从这个 link 获取代码。 .我通过添加新的 CollectionView xib 文件对其进行了修改,并将相应的 swift 文件附加到新的 xib 文件中。我已经在第一个 TableView 单元格中成功初始化了图像和标签
struct Colors {
var objectsArray = [
TableViewCellModel(
category: "ALL DEALS",
headerButton: UIButton.init(),
colors: [
[CollectionViewCellModel(image: UIImage(named:"Rectangle1x.png")!, dicountAmountLabel: "30%", dicountLabel: "Discount", customerTypeLabel: "For All HBL Customers"),
CollectionViewCellModel(image: UIImage(named:"Rectangle2.png")!, dicountAmountLabel: "30%", dicountLabel: "Discount", customerTypeLabel: "For All HBL Customers")]
])
,
TableViewCellModel(
category: "CATEGORIES",
colors: [
// SubCategory #2.1
[CollectionViewCellModelButton(collectionButton:UIButton.init()),
CollectionViewCellModelButton(collectionButton:UIButton.init()),
CollectionViewCellModelButton(collectionButton:UIButton.init()),
CollectionViewCellModelButton(collectionButton:UIButton.init())]
])
]
}
这是我的 UICollectionViewCell
import UIKit
class CollectionViewCellButton: UICollectionViewCell {
@IBOutlet var collectionButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
这是我的模型结构
import Foundation
import UIKit
struct CollectionViewCellModelButton {
var collectionButton: UIButton!
}
如何使用 CollectionViewCellModelButton 中的名称初始化第二个 tableView Cell 中的按钮?
CollectionViewCellModelButton(collectionButton:UIButton.init()) 行出现语法错误如何纠正?
错误是
无法将“CollectionViewCellModelButton”类型的值转换为 预期元素类型 'Array.ArrayLiteralElement'(又名 'CollectionViewCellModel')
【问题讨论】:
标签: ios swift xcode uitableview uicollectionview