I have a tableview setup like shown below. I want the user to only select the checkmark on right side and not the row. User can select multiple checkmarks. Now I want to get the data of all the rows whose checkmark is selected when 'Add Listing' is pressed . Had it been a default cell checkmark, it was easy , but i can't figure out for that one.
Here is the code of TableViewCell
class FacilitiesTableViewCell: UITableViewCell {
@IBOutlet weak var facility: UILabel!
@IBOutlet weak var checkMark: UIButton!
@IBAction func SetCheckMark(_ sender: UIButton) {
if checkMark.isSelected == true {
checkMark.setImage(UIImage(named: "Checkbox"), for: .normal)
checkMark.isSelected = false
print("Button Pressed")
}
else {
checkMark.setImage(UIImage(named: "UnCheckbox"), for: .normal)
checkMark.isSelected = true
}
}
}
Here is the code of my UIViewController Class
class OwnerAddListingFacilitiesViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
let Facilities : [String] = ["AC", "Geaser", "Wifi","Telephone", "TV","Kitchen","Cable","Heater"]
var FacilitiesTaken : [String] = []
override func viewDidLoad() {
super.viewDidLoad()
//tableView.allowsSelection = false
}
@IBAction func addListingTapped(_ sender: UIButton) {
print(FacilitiesTaken)
}
}
extension OwnerAddListingFacilitiesViewController : UITableViewDelegate,UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Facilities.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! FacilitiesTableViewCell
cell.facility.text = Facilities[indexPath.row]
cell.SetCheckMark(cell.checkMark)
return cell
}
And thats the Image of My tableView Screen