我有一个表格视图,该表格视图按日期升序对核心数据进行排序,我想将已经过去的日期放在表格视图的底部。
override func viewWillAppear(_ animated: Bool) {
let fetchRequest: NSFetchRequest<Reminder> = Reminder.fetchRequest()
let sort = NSSortDescriptor(key: #keyPath(Reminder.date),ascending: true)
fetchRequest.sortDescriptors = [sort]
let reminders = try! PersistenceController.context.fetch(fetchRequest)
self.remindersArray = reminders
self.tableView.reloadData()
}
override func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath) as? MainTableViewCell
cell!.titleLabel.text = remindersArray[indexPath.row].title
cell!.dateLabel.text = DateAssist.DateToString(remindersArray[indexPath.row].date!)
cell!.timeLabel.text = DateAssist.TimeToString(remindersArray[indexPath.row].date!)
// }
return cell!
}