gpt4 book ai didi

xcode - 如何首先将新数据加载到 TableView - Swift

转载 作者:行者123 更新时间:2023-11-28 06:56:19 24 4
gpt4 key购买 nike

因此,对于一个学校项目,我必须制作一个宣誓词 jar ,一切都已完成,但我需要知道如何在 UITableView 的顶部而不是底部显示最新的宣誓词。

干杯

最佳答案

dataSource 的排序顺序由您决定,当您设置 dataSource 时,您可以按 class/中的任何属性排序struct 等,这是它呈现给用户的顺序。当您使用 cellForRowAtIndexPath: 填充您的 UITableView 时,它假定您的 dataSource 的顺序,如以下代码所示:

var array = ["Item 1", "Item 2", "Item 3"]

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// here is populated your tableview in the same order of your dataSource is specified if you want it.

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell!
cell.textLabel?.text = array[indexPath.row]

return cell
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

// Return the number of rows in the section.
return array.count
}

您应该看到一个 UITableView,第一行是 Item 1,第二行是 Item 2Item 3在第三个。

希望对你有帮助

关于xcode - 如何首先将新数据加载到 TableView - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33510864/

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