我有表格视图,在表格视图单元格上,单选按钮已放置,当我选择一个单选按钮时,单选按钮可能会动态增加或减少,其他按钮不应一次激活,这是我用于选择按钮的代码但我无法一次使其他按钮处于非活动状态
func paymentMethodURL() {
let url = NSURL(string: self.paymentmethodURL)
URLSession.shared.dataTask(with: (url as URL?)!, completionHandler: {(data, response, error) -> Void in
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
self.paymentmethodsArray = (jsonObj!.value(forKey: "payment method") as? [[String: AnyObject]])!
OperationQueue.main.addOperation({
self.tableDetails.reloadData()
})
}
}).resume()
}
func paymentreviewURL() {
let url = NSURL(string: self.paymentReviewURL)
URLSession.shared.dataTask(with: (url as URL?)!, completionHandler: {(data, response, error) -> Void in
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
let arrayss = jsonObj?.allKeys
OperationQueue.main.addOperation({
})
}
}).resume()
}
@IBAction func selectRadioButton(_ sender: KGRadioButton) {
sender.isSelected = !sender.isSelected
if sender.isSelected {
} else{
}
}
func numberOfSections(in tableView: UITableView) -> Int{
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return paymentmethodsArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let paymentcell = tableView.dequeueReusableCell(withIdentifier: "cell",for:indexPath) as! paymentTableViewCell
tableDetails.isHidden = false
myActivityIndicator.stopAnimating()
let arr = self.paymentmethodsArray[indexPath.row]
paymentcell.paymentNameLabel.text = arr["name"]as? String
return paymentcell
}
var checkIsRadioSelect = [Int]()
var webserviceArray = [modelObj]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let obj = webserviceArray[indexPath.row]
cell.radioButton.tag = indexPath.row
let checkIndex = self.checkIsRadioSelect.index(of: obj.wateverUniqeId)
if(checkIndex != nil){
cell.radioButton.isSelected = true
}else{
cell.radioButton.isSelected = false
}
}
@IBAction func selectRadioButton(_ sender: UIButton) {
let obj = webserviceArray[sender.tag]
let chekIndex = self.checkIsRadioSelect.index(of:obj.wateverUniqeId)
if sender.isSelected {
self.checkIsRadioSelect.remove(at: sender.tag)
} else{
if(chekIndex == nil){
self.checkIsRadioSelect.append(obj.wateverUniqeId)
}
} self.tableview.reloadData()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句