Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 如何首先将最新数据加载到UITableView-Swift_Xcode_Swift_Uitableview - Fatal编程技术网

Xcode 如何首先将最新数据加载到UITableView-Swift

Xcode 如何首先将最新数据加载到UITableView-Swift,xcode,swift,uitableview,Xcode,Swift,Uitableview,因此,对于一个学校项目,我必须制作一个咒语罐,一切都已完成,但我需要知道如何在UITableView的顶部而不是底部显示最新的咒语 干杯只要把脏话放在数组的开头。你的数据源的顺序由你决定,当你设置数据源时,你可以按你的类/结构中的任何属性排序,等等,这是它呈现给用户的顺序。当您使用单元格FORROWATINDEXPATH:填充UITableView时,它假定数据源的顺序,如下代码所示: var array = ["Item 1", "Item 2", "Item 3"] override fu

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


干杯

只要把脏话放在数组的开头。

你的
数据源
的顺序由你决定,当你设置
数据源
时,你可以按你的
类/结构
中的任何属性排序,等等,这是它呈现给用户的顺序。当您使用
单元格FORROWATINDEXPATH:
填充
UITableView
时,它假定数据源的顺序,如下代码所示:

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
,第一行显示
项目1
,第二行显示
项目2
,第三行显示
项目3


我希望这对你有帮助。

是的,这对你有帮助,对不起,我在课堂上的描述很简短。在将数据保存到另一个视图控制器后,我正在从core data加载数据。这没有问题,只需在将数据传递到
UITableViewController
UIViewController
之前对数据进行排序,它将帮助您。我正在尝试,但它会告诉我“发生错误-请重试您的请求”我保证今晚为你完成这件事