【发布时间】:2017-06-21 14:00:24
【问题描述】:
在这里我实现了一个自定义设计,如图像shown here 我需要根据我的 Web 服务数据激活单选按钮。在 Web 服务中,我只收到 0 和 1 的一个键值对,如果它是 1,那么我需要激活单选按钮来帮助如何实现?
这是我的单选按钮的代码
@IBAction func selectRadioButton(_ sender: KGRadioButton) {
let chekIndex = self.checkIsRadioSelect.index(of: sender.tag)
let checkIndex = self.checkIsButtonEnable.index(of: sender.tag)
if sender.isSelected {
} else{
if(chekIndex == nil){
self.checkIsRadioSelect.removeAll(keepingCapacity: false)
self.checkIsRadioSelect.append(sender.tag)
self.checkIsButtonEnable.removeAll(keepingCapacity: false)
self.checkIsButtonEnable.append(sender.tag)
self.tableDetails.reloadData()
}
}
}
这是表格视图的代码
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! addressTableViewCell
tableDetails.isHidden = false
myActivityIndicator.stopAnimating()
let arr = detailsArray[indexPath.row]
cell.nameLabel.text = arr["name"]as? String
cell.addressLabel.text = arr["address"]as? String
let mobilenumber : Int = arr["number"] as! Int
cell.mobileNumberLabel.text = String(describing: mobilenumber)
let defaultaddress : Int = arr["default"] as! Int
cell.radioButton.tag = indexPath.row
cell.editButton.tag = indexPath.row
cell.deleteButton.tag = indexPath.row
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row)
if(checkIndex != nil){
cell.radioButton.isSelected = true
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
}else{
cell.radioButton.isSelected = false
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
}
return cell
【问题讨论】:
-
我没有告诉你是否需要使用 API 数据显示单选按钮的状态。或者您想在单击时更新单选按钮状态?
-
我需要两者都有,但对于第一次加载应用程序,它应该从 api 获取并根据我的数据激活单选按钮,稍后我需要手动更改它
-
手动我已经设置,我还需要设置 api 数据@DSDharma
-
检查我的答案..
标签: ios uitableview swift3