gpt4 book ai didi

uitableview - 您可以不使用 cellForRowAtIndexPath 方法来填充 UITableView 吗?

转载 作者:行者123 更新时间:2023-11-28 07:08:33 24 4
gpt4 key购买 nike

我问的原因是因为我有一个对象字典,我想用它来填充我的 UITableView。由于 Dictionary 具有键和值的对象,我不确定如何用它填充 UITableView。我知道填充 UITableView 的唯一方法是使用需要索引 (indexPath.row) 的 cellForRowAtIndexPath,并且由于我的 Dictionary 是对象的集合,所以我无法通过索引引用每个对象。

有谁知道您是否可以在不使用 cellForRowAtIndexPath 方法的情况下填充 UITableView?或者,有没有办法使用 cellForRowAtIndexPath 将对象的字典填充到 UITableView?

最佳答案

根据我的评论:

Dictionaries do not have a fixed order, so this would possibly yield different results on each run of the app.

因此将字典转换为键/值元组数组。将字典转换为数组(根据需要替换正确的类型):

let dictionary = ["a" : 1, "b" : 2, "c" : 3]
var array = [(String, Int)]()

for tuple in dictionary {
array.append(tuple)
}

println(array)

输出:

[(b, 2), (a, 1), (c, 3)]

关于uitableview - 您可以不使用 cellForRowAtIndexPath 方法来填充 UITableView 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29478589/

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