菜鸟教程小白 发表于 2022-12-13 01:39:51

iphone - 选择 UITableView 中的所有单元格,甚至是 iOS 中的不可见单元格


                                            <p><p>我有一个方法 selectAll 可以选择 <code>UITableView</code> 中的所有单元格。这个方法检查一个复选框<code>(UIButton)</code>。它仅适用于 <code>"visible"</code> 单元格,但不适用于 <code>"invisible"</code> 单元格!</p>

<p>这是我的方法:</p>

<pre><code>- (IBAction)selectAll:(id)sender {

    for (NSInteger s = 0; s &lt; self.tableView.numberOfSections; s++) {
      for (NSInteger r = 0; r &lt; ; r++) {

            CustomCell *cell = ];

            if(!cell.checkbox.selected){
                cell.checkbox.selected = !cell.checkbox.selected;
                cell.account.checked = cell.checkbox.selected;
            }

      }
    }   
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>来自文档:</p>

<pre><code>cellForRowAtIndexPath:
</code></pre>

<p>返回值:</p>

<blockquote>
<p>An object representing a cell of the table or <code>nil if the cell is not visible</code> or indexPath is out of range.</p>
</blockquote>

<p>您可以创建一个数组,其中包含选中或未选中的 bool 值列表,并在单元格可见时对其进行查询。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 选择 UITableView 中的所有单元格,甚至是 iOS 中的不可见单元格,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15543324/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15543324/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 选择 UITableView 中的所有单元格,甚至是 iOS 中的不可见单元格