菜鸟教程小白 发表于 2022-12-11 19:12:31

ios - 单选按钮选择时的原型(prototype)单元重用


                                            <p><p>在自动选择其他单元格单选按钮时选择 cell1 上的单选按钮时,我需要在一个单元格上设置一个单选按钮,我有许多带有 5 个或更多单选按钮的单元格
<a href="/image/N9ewo.png" rel="noreferrer noopener nofollow"><img src="/image/N9ewo.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在这里,您需要从单选按钮维护所选项目的列表/项目。
在 tableview 中的 didSelectRowAt 中,您可以执行以下步骤如果您使用字符串进行检查,则可以从选项 id 库中执行。</p>

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

<p>在 cellForRowAt 中,您可以执行以下步骤</p>

<pre><code>if (isItemSelected(optionText: answerOption) == true) {
   answerCell.answerOption?.image = UIImage(named: &#34;radio_on&#34;)
}
else {
   answerCell.answerOption?.image = UIImage(named: &#34;radio_off&#34;)
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 单选按钮选择时的原型(prototype)单元重用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42712297/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42712297/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 单选按钮选择时的原型(prototype)单元重用