2017-07-02 25 views
1

我有一個UITextView在UITableViewCell中顯示特定的評級。我怎樣才能排序UITableView的方式,文本瀏覽按照從高到低的順序排序?這是我的文本框的代碼,以防您需要它:如何對UITableViewCell中的textview中的數字進行排序?

let scoreText = UITextView() 
           scoreText.font = UIFont.systemFont(ofSize: 13.5) 
           scoreText.text = (String(userRating)) + " ✨" 
           scoreText.textColor = UIColor.gray 
           scoreText.textAlignment = NSTextAlignment.right 
           scoreText.translatesAutoresizingMaskIntoConstraints = false 

回答

0

這不是UITextView的問題。您的UITableView的順序應該達到數據源的順序。例如,

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // In this case YOUR_DATA_LIST needs to be sorted beforehand. 
    return YOUR_DATA_LIST.count 
} 
+0

這工作,謝謝! – Ontop14

+0

你說過「我在UITableViewCell中有一個UITextView」,所以我假設你已經在每個單元格中定製了包含「UITextView」的「UITableViewCell」。如果你這樣做,每個UITextView的數據應該在'tableView(_:cellForRowAt:)'中設置。 – Lawliet

相關問題