OStack程序员社区-中国程序员成长平台

标题: ios - 选择行时奇怪的tableView行/部分动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:39
标题: ios - 选择行时奇怪的tableView行/部分动画

这很酷expanding tableView效果很好,但是当您选择某些行时,会出现奇怪的动画。

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

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

enter image description here

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

    tbl.reloadSections(NSIndexSet(index: indexPath.section), withRowAnimation: .Automatic)

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

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

编辑 - 还尝试了 insertRowsAtIndexPath 和 deleteRowsAtIndexPath 但它似乎与 tableView 模型的设置方式和应用程序崩溃相冲突。



Best Answer-推荐答案


在表格中插入行应该可以帮助您获得更一致的表格 View 动画行为。

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

对象:

NSArray* arr = your NSIndex Paths...;

[tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];

swift :

table.insertRowsAtIndexPaths([IndexPaths..], withRowAnimation: .Automatic)

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/insertRowsAtIndexPaths:withRowAnimation :

关于ios - 选择行时奇怪的tableView行/部分动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37622216/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4