OGeek|极客世界-中国程序员成长平台

标题: ios - 单选按钮选择时的原型(prototype)单元重用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:12
标题: ios - 单选按钮选择时的原型(prototype)单元重用

在自动选择其他单元格单选按钮时选择 cell1 上的单选按钮时,我需要在一个单元格上设置一个单选按钮,我有许多带有 5 个或更多单选按钮的单元格 enter image description here



Best Answer-推荐答案


在这里,您需要从单选按钮维护所选项目的列表/项目。 在 tableview 中的 didSelectRowAt 中,您可以执行以下步骤如果您使用字符串进行检查,则可以从选项 id 库中执行。

selectedItem.removeAllObjects() // AS radio button is kept only one selected at a time.
selectedItem.add(currentCell.answerLabel?.text)
self.tableView?.reloadData()

在 cellForRowAt 中,您可以执行以下步骤

if (isItemSelected(optionText: answerOption) == true) {
   answerCell.answerOption?.image = UIImage(named: "radio_on")
 }
 else {
   answerCell.answerOption?.image = UIImage(named: "radio_off")
 }

关于ios - 单选按钮选择时的原型(prototype)单元重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42712297/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4