菜鸟教程小白 发表于 2022-12-11 16:39:03

ios - 选择行时奇怪的tableView行/部分动画


                                            <p><p>这很酷<a href="https://github.com/appcoda/expandable-table-view" rel="noreferrer noopener nofollow" title="expanding tableView">expanding tableView</a>效果很好,但是当您选择某些行时,会出现奇怪的动画。 </p>

<p>表格有多个部分,每行在点击时可以显示额外的行。行的外观和行为是在使用各种值的 plist 中构建的,例如如果 plist 中某一行的 bool “isExpandable”属性设置为 true,并且其“additionalRows”属性设置为 2,则该行可以展开以显示 2 个子行。</p>

<p>表格的问题是,当点击每个部分的第一个单元格时,动画运行良好,但是当点击其他单元格时,它们会随机播放:-</p>

<p> <a href="/image/s6N45.gif" rel="noreferrer noopener nofollow"><img src="/image/s6N45.gif" alt="enter image description here"/></a> </p>

<p>我怀疑会出现奇怪的动画,因为在 ViewController 文件中的 didSelectRowAtIndexPath 下的这一行导致单击单元格时所有部分都会重新加载:-</p>

<pre><code>    tbl.reloadSections(NSIndexSet(index: indexPath.section), withRowAnimation: .Automatic)
</code></pre>

<p>我尝试了以下方法,但它们要么使应用程序崩溃,要么导致单元格无法扩展:-</p>

<ul>
<li>将动画方法设置为 .None</li>
<li>改用 reloadData</li>
<li>存储 selectedRow 及其子行的 indexPaths,然后用 reloadIndexPaths 重新加载所有</li>
<li>存储所选单元格及其子单元格的行,然后在单击一行时重新加载它们一次</li>
</ul>

<p>在实际发布代码的网站上有人建议使用 insertRowsAtIndexPath 和 deleteRowsAtIndexPath 而不是 reloadSection,但我不知道该怎么做。非常感谢您的帮助。</p>

<p><strong>编辑</strong>
- 还尝试了 insertRowsAtIndexPath 和 deleteRowsAtIndexPath 但它似乎与 tableView 模型的设置方式和应用程序崩溃相冲突。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在表格中插入行应该可以帮助您获得更一致的表格 View 动画行为。</p>

<p>要在特定索引路径插入行,您可以使用“insertRowsAtIndexPaths”方法。您将需要生成要插入的每个索引路径,然后将它们传递给数组中的方法。 </p>

<p>对象:</p>

<pre><code>NSArray* arr = your NSIndex Paths...;

;
</code></pre>

<p> swift :</p>

<pre><code>table.insertRowsAtIndexPaths(, withRowAnimation: .Automatic)
</code></pre>

<p> <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/insertRowsAtIndexPaths:withRowAnimation" rel="noreferrer noopener nofollow">https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/insertRowsAtIndexPaths:withRowAnimation</a> :</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 选择行时奇怪的tableView行/部分动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37622216/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37622216/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 选择行时奇怪的tableView行/部分动画