我有一个表格视图,它发出一个请求,并在请求结束后向其中提供新数据。除了要使用自定义对象的一个单元格之外,我在表视图中想要的每个值都会更改。她
let cell = tableView.dequeueReusableCell(withIdentifier: "otherCell", for: indexPath) as! OtherCell
cell.selectionStyle = .none
cell.humidityValue = weather.currentHumidity
return cell
-
class OtherCell: UITableViewCell {
var humidityValue = ""
override init(style: UITableViewCellStyle, reuseIdentififier: String?) {
let humidityView = Other(icon: UIImage(named: "humid")!, label: "Humidity", value: humidityValue, side: 0).createView()
view.addSubview(humidityView)
}
}
class Other {
var icon = UIImageView()
var label = ""
var value = ""
init(icon: UIImage, label: String, value: String, side: Int) {
self.icon = UIImageView(image: icon)
self.label = label
self.value = value
self.side = side
}
func createView() -> UIView {
let view = UIView()
view.backgroundColor = .clear
let l = UILabel()
let v = UILabel()
l.text = label
l.textColor = UIColor.lightGray
l.font = UIFont.customBoldFont(size: 15)
v.text = value
v.textColor = UIColor.softBlack()
v.font = UIFont.customBoldFont(size: 25)
let labelStackView = UIStackView(arrangedSubviews: [l, v])
labelStackView.axis = .vertical
labelStackView.alignment = .leading
view.addSubview(icon)
icon.anchor(top: nil, left: view.leftAnchor, bottom: nil, right: nil, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 55, height: 55)
view.addSubview(labelStackView)
labelStackView.anchor(top: icon.topAnchor, left: icon.rightAnchor, bottom: icon.bottomAnchor, right: nil, paddingTop: 0, paddingLeft: 10, paddingBottom: 0, paddingRight: 0, width: 0, height: 0)
return view
}
}