jeudi 8 août 2019

How can I call the action of a checkbox button when the cell is touched?

I'm using a custom cell which contains a label and a button. In my button, i've an action associated with it i.e when the button is touched the button changes its image and changed to checked image. But i want that action to be call when entire cell is touched.

extension HostOptionViewController: UITableViewDataSource, UITableViewDelegate{

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return Question.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let question = Question[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "QuestionOptionCell") as! ViewCellTableViewCell
        cell.setText(option: question)
        arrayOfCells.append(cell)
        return cell
    }

In my Custom cell

import UIKit

class ViewCellTableViewCell: UITableViewCell {
    @IBOutlet weak var DataCell: UILabel!
    @IBOutlet weak var checkBox: UIButton!

    @IBAction func CheckBoxFunc(_ sender: Any) {
        if checkBox.isSelected{
            checkBox.isSelected = false
        }
        else{
            checkBox.isSelected = true
        }
    }

    func setText(option: Data){
        DataCell.text = option.data
    }
}

I want to call "CheckBoxFunc" when the cell is touched.

Action for the button.




Aucun commentaire:

Enregistrer un commentaire