问题描述
我有一个典型的UITableView
,带有自定义单元格。所有单元格都属于同一类型-一个UIStackView包含相同类型的视图,但其计数有所不同。
试图全部使用一个单元格-删除-添加内部视图很慢。
试图为不同数量的子视图创建不同的单元格:
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = rows[indexPath.row]
let CellIdentifier = "CellIdentifier\(row.subrows.count)"
var cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier) as? CustomCell
if cell == nil {
tableView.register(UINib(nibName: "WTRemindersTableViewCell",bundle: nil),forCellReuseIdentifier: CellIdentifier)
cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier) as? CustomCell
for _ in row.subrows {
let v = Bundle.main.loadNibNamed("CustomInnerView",owner: self,options: nil)?.first as! WTRemindersCellLineView
cell!.stackView.addArrangedSubview(v)
}
}
return cell!
}
但是似乎它只注册一个没有子视图的单元,并且使用不同的单元标识符也没有意义(因为每次您都需要手动添加stackview子视图)。
如何解决此问题?
已编辑
为单元格添加了代码
class CustomCell: UITableViewCell {
@IBOutlet var boxView: UIView!
@IBOutlet var imgView: UIImageView!
@IBOutlet var lblTitle: UILabel!
@IBOutlet var lblSubtitle: UILabel!
@IBOutlet var dashedView: WTDashedView!
@IBOutlet var stackView: UIStackView!
weak var delegate: CustomCellDelegate?
var index: Int!
lazy var onceDraw: () = {
boxView.layer.applySketchShadow()
}()
override func awakeFromNib() {
super.awakeFromNib()
boxView.layer.cornerRadius = 19
imgView.layer.cornerRadius = 12
}
override func draw(_ rect: CGRect) {
super.draw(rect)
_=onceDraw
}
@IBAction func btnDotsClicked(_ sender: Any) {
delegate?.btnDotsClicked(at: index)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)