我有一个带有 customCell 的 UITableView,其中我有一个标签,将每行的编号显示为 1,2,3,4...,4 是表格底部的最后一行。一切正常,但我想反转数字而不是 4、3、2、1,其中 4 是顶行,1 是最后一行。
这是我用来将数字添加到 customCell 中的标签的代码。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reusableCell", forIndexPath: indexPath) as! CustomCell
cell.labelRowNumber!.text = String(indexPath.row + 1)// how to reverse the indexPath.row
return cell
}
如果不添加一个数组来跟踪每一行的数量,这是否可能?
仅供引用 - 我已经反转添加到表中的内容,它来自数组 itemList.insert(dataCell, atIndex:0)
。我只需要反转数字以匹配内容。
谢谢
最佳答案
你只需要以相反的顺序得到值:
cell.labelRowNumber!.text = String(count - indexPath.row)
其中 count 是您显示的行数(即无论您从 numberOfRowsInSection 返回什么)。大概是 itemList.count
。
关于ios - 反转UITable行号从大到小(...5,4,3,2,1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35305632/