菜鸟教程小白 发表于 2022-12-13 12:24:06

iphone - 如何从表格 View 中完全隐藏某个单元格?


                                            <p><p>我有一个简单的问题——我需要从 UITableView 中隐藏某些单元格。
我发现的是委托(delegate)方法 <strong>tableView:heightForRowAtIndexPath:</strong>
这是我的实现:</p>

<pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
       return 0;
    return 45;   
}
</code></pre>

<p>不幸的是,这不起作用。单元格缩小到一条线,我真的无法理解发生了什么。
任何帮助将不胜感激。谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您必须在 <code>tableView:heightForRowAtIndexPath:</code> 方法中将单元格的高度设置为 0,并通过 <code>hidden</code> 属性隐藏单元格。如果您希望在用户交互后获得此效果,则需要通过 <code>reloadData</code> 重新加载表格。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何从表格 View 中完全隐藏某个单元格?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/9769789/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/9769789/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何从表格 View 中完全隐藏某个单元格?