尚未编辑:
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let arr = ["A","B","C","D","E","F","G","H","I","J","K","L","M"]
@IBOutlet weak var tableView: UITableView!
//----------------------------------------------------------------------------//
override func viewDidLoad() {
super.viewDidLoad()
}
//----------------------------------------------------------------------------//
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Cell
cell.thisIsMyText.text = arr[indexPath.row]
return (cell)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr.count
}
}
答案 0 :(得分:3)
var sortedArray: [String] = []
...
sortedArray = arr.sorted()
和
cell.thisIsMyText.text = sortedArray[indexPath.row]