gpt4 book ai didi

ios - 是否可以从 NSIndexPath 获取 "global"索引?

转载 作者:行者123 更新时间:2023-11-28 19:35:54 25 4
gpt4 key购买 nike

如果我在 UITableView 属性上有不同的部分,NSIndexPath.row 会给我当前部分的索引。

是否可以在不考虑节的情况下获取表格中单元格的绝对索引?

例如:如果一个表有 2 个部分,第一个部分有 10 个项目,我想为第二个部分的第一个元素获取索引 = 10。

最佳答案

我同意一些评论,认为这可能不是实现无限滚动的最佳方式。虽然回答你最初的问题,你可以在 Swift 中做这样的事情:

extension UITableView {
func globalIndexPath(for localIndexPath: NSIndexPath) -> Int {
var totalRows = 0
for i in 0..<localIndexPath.section {
totalRows += self.numberOfRowsInSection(i)
}
return totalRows + localIndexPath.row
}
}

关于ios - 是否可以从 NSIndexPath 获取 "global"索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38899773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com