0

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
}
CFRJ
  • 157
  • 1
  • 12
  • Post your code, please – Avt Jul 08 '17 at 09:24
  • added the code :) – CFRJ Jul 08 '17 at 09:29
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Cristik Mar 19 '18 at 06:01

0 Answers0