In my application multiple sections. checkbox and radio button.
In tableview cell created a two UIButton, depends upon the response change the button, if its checkbox or radio button.
here my code.
func numberOfSections(in tableView: UITableView) -> Int {
return table_data.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return table_data[section].menu_id.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:CustomiseTableViewCell = tableView.dequeueReusableCell(withIdentifier: "Customise") as! CustomiseTableViewCell
cell.name.text?=table_data[indexPath.section].menu_name[indexPath.row]
print(table_data[indexPath.section].customize[indexPath.row])
switch Int(table_data[indexPath.section].customize[indexPath.row]) {
case 1:
cell.radioBtn.isHidden = true
cell.checkBoxBtn.isHidden = false
break
case 2:
cell.radioBtn.isHidden = false
cell.checkBoxBtn.isHidden = true
break
default:
print("Invalid choose")
}
cell.radioBtn.addTarget(self, action: #selector(ViewController.radioBtnaction), for: .touchUpInside)
cell.checkBoxBtn.addTarget(self, action: #selector(ViewController.checkBoxBtnaction), for: .touchUpInside)
return cell
}
table_data is array, and the array values are get from web services using struct.
My problem:
write the button action for radio button.
func radioBtnaction(sender: UIButton)
{
}
In button click action choice is one separate sections in tableview show in image. In that sections want to select and deselect the radio button. when select cheese it will selected, then i will select the triple layer cheese means, cheese automatically deselect. want to select only one item in that sections.
Each sections have a different item with radio button.
if selected one radio button it will select, after selected any other radio button means the pervious selected button want to deselect automatically. it want to happend in each sections in tableview only for radio button.
want ever the item selected want to store it in string.
The same button action need for check box with multiple selection.
func checkBoxBtnaction(sender:UIButton)
{
}
enter image description here
help me thanks advance.
Aucun commentaire:
Enregistrer un commentaire