Hi I'm trying to add radiobuttons to my tableview. I have a tableviewcell class connected to the button in the tableview but when I try to add the button inside cellForRowAt indexpath function the app crash with error: unexpectedly found nil while unwrapping an Optional value
TableViewCell Code
import UIKit
class TableViewCell: UITableViewCell, SSRadioButtonControllerDelegate {
@objc func didSelectButton(selectedButton: UIButton?) {
NSLog(" \(selectedButton)" )
}
@IBOutlet var radioButton: UIButton!
@IBOutlet var taskText: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
TableViewController Code
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
self.title = "Today"
//Radio buttons
radioButtonController.delegate = self
radioButtonController.shouldLetDeSelect = true
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = TableViewCell(style: .default, reuseIdentifier: "Cell")
let task = tasks[indexPath.row]
radioButtonController.addButton(cell.radioButton)
if let myName = task.name {
cell.textLabel?.text = myName
}
return cell
}