我有一个表格 View ,其中这些字段填充了表格。 locTextArray 包含以英尺为单位的距离。
如何将单元格按英尺数量从最少到最多排序?
我想我可以对数组进行排序,但这会与所有其他数组不匹配。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell : MainViewCell! = tableView.dequeueReusableCellWithIdentifier("MainCell") as! MainViewCell
cell.cellTitle.text = nameArray[indexPath.row] //title
cell.cellText.text = textArray[indexPath.row] // text
let formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
cell.userCount.text = formatter.stringFromNumber(Double(priceArray [indexPath.row])!) //price
cell.cellDate.text = timeArray[indexPath.row] //time
cell.cellAddress.text = locTextArray [indexPath.row] //distance in feet
return cell as MainViewCell
}
最佳答案
如果您使用对象,一切都会更容易。创建具有属性(名称、文本、价格、时间、locText)的自定义对象。使用其中的一个数组来控制表数据并按任何有意义的属性对其进行排序。
然后你的代码会变成这样:
let obj = objArray[indexPath.row]
cell.cellTitle.text = obj.name
cell.cellText.text = obj.text
// ...
关于arrays - 从最低到最高对表格 View 单元格进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36752584/