這裏我實現了一個自定義設計,如圖像shown here我需要激活單選按鈕取決於我的Web服務數據。在Web服務中,一個關鍵值對我只能接收0 & 1,如果它是1,那麼我需要激活單選按鈕,如何實現該幫助?如何啓用單選按鈕取決於來自Web服務的數據?
這裏是我的單選按鈕
@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 –