gpt4 book ai didi

ios - 如何实现一个单选按钮在选择时处于事件状态?

转载 作者:行者123 更新时间:2023-11-29 00:18:29 28 4
gpt4 key购买 nike

我有表格 View ,在表格 View 单元格上放置了单选按钮,当我选择一个单选按钮时,单选按钮可能会动态增加或减少,其他按钮不应同时激活这里是我用于的代码选择一个按钮,但我无法一次使其他按钮处于非事件状态

 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 tagSelected = -1

//假设每个单选按钮都有标签 0 1 2

@IBAction func selectRadioButton(_ sender: KGRadioButton) {
tagSelected = sender.tag
tableView.reloadData()
}

//RowAtIndexPath 的单元格

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

guard let cell = tableView.dequeueReusableCell(withIdentifier:
kCellReuseIdentifier, for: indexPath) as? YourCell else {
fatalError("Cell is not dequeued")
}

//logic for match indexPath.row /section to your button tags
if indexPath.row == tagSelected {
//selected here your radio button
} else {
//unselect all others
}
//other code

return cell
}

关于ios - 如何实现一个单选按钮在选择时处于事件状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44675583/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com