首页 > 解决方案 > 以编程方式增加 indexPath

问题描述

如何以var编程方式增加 indexPath 类型的?例如,当前 indexPath 是 [0, 44],我希望在特定操作后 indexPath 是 [0,45]?

标签: swiftuicollectionview

解决方案


由于您正在使用集合视图,因此您似乎想要增加该item属性。

someIndexPath.item += 1

如果需要,您还可以IndexPath在旧的基础上创建一个新的:

let newIndexPath = IndexPath(item: oldIndexPath.item + 1, section: oldIndexPath.section)

推荐阅读