zoukankan      html  css  js  c++  java
  • UITableView beginUpdate和endUpdate使用的前提

    转载地址:http://blog.csdn.net/vieri_ch/article/details/46893023

    UITableView有两个方法,用于单元格动画变化的方法,beginUpdate,endUpdate,这两个方法使用时需要注意。如果使用不当,会造成crash
    在了解使用注意事项之前,我们先看官方文档的描述。

    Call this method if you want subsequent insertions, deletion, and
    selection operations (for example, cellForRowAtIndexPath: and
    indexPathsForVisibleRows) to be animated simultaneously. You can also
    use this method followed by the endUpdates method to animate the
    change in the row heights without reloading the cell. This group of
    methods must conclude with an invocation of endUpdates. These method
    pairs can be nested. If you do not make the insertion, deletion, and
    selection calls inside this block, table attributes such as row count
    might become invalid. You should not call reloadData within the group;
    if you call this method within the group, you must perform any
    animations yourself.

    从描述中,可以了解到以下几点
    1. 这个方法用于在调用插入,删除,选择方法时,同时有动画效果。
    2. 用endUpdate能动画改变行高,而无需relaod这个cell。
    3. beginUpdate和endUpdate成对使用,其包含的block里面,如果没有插入删除,选择的方法被使用。有可能导致这个table view的一些属性失效,例如行的数量。
    4. 不应该在这个block范围里调用 reloadData,或者reloadRowsAtIndexPaths。一旦使用,必须自己执行和管理自己的动画效果。

    第三点和第四点比较重要。也是导致闪退的原因。reloadData会引起,获取单元格高度,以及cell的重新加载。这会导致一些动画对应的行号产生变化。从而闪退。

  • 相关阅读:
    Java提高篇——通过分析 JDK 源代码研究 Hash 存储机制
    Java提高篇——equals()与hashCode()方法详解
    Java提高篇——equals()方法和“==”运算符
    Java提高篇—— 简单介绍Java 的内存泄漏
    Java提高篇——理解String 及 String.intern() 在实际中的应用
    hbuilder
    angular
    微信小程序
    angular
    angular
  • 原文地址:https://www.cnblogs.com/AbeDay/p/5026892.html
Copyright © 2011-2022 走看看