【发布时间】:2017-08-19 07:43:28
【问题描述】:
在 tableview 中有不同的部分。
想要为所有部分添加单选按钮。
每个部分在表格视图中都有单独的选择和取消选择。
在第一部分choice1,[如图所示]
Selected cheese 表示要选择的奶酪,下一步如果用户点击 bacon 表示奶酪自动取消选择。
[这里使用单选按钮 SSRadioButton 类进行点击操作。在 tableview 单元格中创建一个单选按钮。如何编写单选按钮的按钮操作。或提出任何新的方法]。
每个单选按钮都需要单独选择和取消选择。表格视图中所有部分的相同过程。怎么可能帮助我。谢谢提前。
我的代码:
var radioControllerChoice : SSRadioButtonsController = SSRadioButtonsController()
var radioControllerDip : SSRadioButtonsController = SSRadioButtonsController()
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 indexPath.section {
case 2:
radioControllerChoice.addButton(cell.radioBtn)
radioControllerChoice.shouldLetDeSelect = false
case 3:
radioControllerDip.addButton(cell.radioBtn)
radioControllerDip.shouldLetDeSelect = false
switch Int(table_data[indexPath.section].customize[indexPath.row]) {
case 1:
cell.radioBtn.isHidden = false
default:
print("Invalid choose")
cell.radioBtn.addTarget(self, action: #selector(ViewController.didSelectButton), for: .touchUpInside)
cell.radioBtn.tag = indexPath.row
}
}
}
func didSelectButton(selectedButton: UIButton?)
{
/// need solution for button action help me..
}
【问题讨论】:
-
最好包含代码的相关部分,例如
cellForRow和didSelectRow方法以及您的数据源,以便我们帮助您解决问题 -
你能分享任何代码来解决这个问题吗..我正在努力..
-
我可以给出一个通用的答案,这可能会或可能不会帮助你,但如果你用代码更新你的问题,我可能会帮助你克服这个问题
-
更新我的问题检查一下。
标签: swift radio-button tableview sections