編輯排序
@IBAction func sortby(_ sender: Any) {
let controller = UIAlertController (title: "排序" , message: "新舊" , preferredStyle: .actionSheet)
let names = [ "新->舊" , "舊->新" ]
for name in names {
let action = UIAlertAction(title: name, style: .default) { [self] action in
if action.title == names[0] {
self.iteamTabel.sort(by: { m1, m2 in
m1.timeStamp > m2.timeStamp
})
self.tabelview.reloadData()
return sortbybool = true
} else {
self.iteamTabel.sort(by: { m1, m2 in
m1.timeStamp < m2.timeStamp
})
self.tabelview.reloadData()
return sortbybool = false
}
}
controller.addAction(action)
}
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
controller.addAction(cancelAction)
present(controller, animated: true)
}