I would like to know if someone has a way to get the value of a class UITableViewCell
.
class EncuestaRespuestaC: UITableViewCell {
@IBOutlet weak var lblDescription: UILabel!
@IBOutlet weak var ivStart01: UIButton!
@IBOutlet weak var ivStart02: UIButton!
@IBOutlet weak var ivStart03: UIButton!
@IBOutlet weak var ivStart04: UIButton!
@IBOutlet weak var ivStart05: UIButton!
private var starts : [UIButton]!
public var position = 0
override func awakeFromNib() {
super.awakeFromNib()
initView()
}
private func initView() {
starts = [ivStart01, ivStart02, ivStart03, ivStart04, ivStart05]
for start in starts {
start.addTarget(self, action: #selector(onClick(_:)), for: .touchUpInside)
}
}
@objc private func onClick( _ button: UIButton) {
position = button.tag
setStart(position: position)
position += 1
}
private func setStart(position: Int) {
for (index, start) in starts.enumerated() {
let color = index <= position ? Colors.Color.PURPLE_BUTTON : Colors.Color.GRIS_BUTTON
setColorFilter(button: start, imageName: "ic_star", color: color)
}
}
}
// Obs Each of my 5 buttons has a tag (1,2,3,4,5)
I want to notify my models
my controller
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let pregunta = preguntas[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: ID_CELL, for: indexPath) as! EncuestaRespuestaC
cell.lblDescription.text = pregunta.nomPregunta
pregunta.respuesta = cell.position
AnimationsUtil.animationTableCell(cell: cell)
cell.selectionStyle = .none
return cell
}
my model is
class EncuestaRespuestaBE: NSObject {
internal var idPregunta: Int? = 0 {
didSet { idPregunta = idPregunta ?? 0 }
}
internal var nomPregunta: String? = "" {
didSet { nomPregunta = nomPregunta ?? "" }
}
internal var respuesta: Int? = 0 {
didSet { respuesta = respuesta ?? 0 }
}
override var description: String {
return "\(EncuestaRespuestaBE.self){ idPregunta: \(idPregunta!), nomPregunta: \(nomPregunta!), respuesta: \(respuesta!) }"
}
}
My intention is to notify the model inside the cell, and when to call the list of surveys. You should get them with the changes of the buttons.