This I what I trying to achieve:
There is no problem in populating all the datas, but the problem is how to let user to choose only one row for radio section and allow more than one row for checkbox section, I am stuck in this part. Here is the code for now:
@objc func checkboxSelected(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
if(sender.isSelected == true)
{
sender.setImage(UIImage(named: "red_checkbox"), for: UIControlState.normal)
}
else
{
sender.setImage(UIImage(named: "checkbox2"), for: UIControlState.normal)
}
}
@objc func radioBtnSelected(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
if(sender.isSelected == true)
{
sender.setImage(UIImage(named: "radio_red"), for: UIControlState.normal)
}
else
{
sender.setImage(UIImage(named: "radio_white"), for: UIControlState.normal)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DishTableViewCell", for: indexPath) as! DishTableViewCell
cell.titleLbl.text = self.menu[indexPath.section].menuOptions[indexPath.row].name
if self.menu[indexPath.section]. menuOptions[0].title == "checkbox" {
cell.checkboxBtn.isHidden = false
cell.radioBtn.isHidden = true
}else if
self.menu[indexPath.section]. menuOptions[0].title == "radio" {
cell.checkboxBtn.isHidden = true
cell.radioBtn.isHidden = false
}
cell.checkboxBtn.addTarget(self, action: #selector(DishViewController.checkboxSelected(_:)), for: UIControlEvents.touchUpInside)
cell.radioBtn.tag = self.menu[indexPath.section]. menuOptions[indexPath.row].id
cell.radioBtn.addTarget(self, action: #selector(DishViewController.radioBtnSelected(_:)), for: UIControlEvents.touchUpInside)
return cell
}
Or is there any other way to do other than using tableview? Please assist. Thank you