ios - 将数组元素及其索引设置为标签
问题描述
嗨,我有一个元素数组
var prices = ["100", "200", "90", "", "", "300", "100"]
和方法 cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellid") as? PriceViewCell
for (index, item) in prices.enumerated() {
cell?.priceLbl.text = "Item \(index): \(item)"
}
return cell ?? UITableViewCell()
}
输出是这样的:
但是首选结果是这样的(标记为红色):
解决方案
我将Joakim Danielson的答案放入一个问题中,以便未来的用户可以更轻松地找到它:
cell?.priceLbl.text = "Item \(indexPath.row + 1): \(prices[indexPath.row])"
推荐阅读
- java - 如何在 feign 客户端尤其是 HTTP 标头中传递标头?
- terraform - 我什么时候需要在 terraform 中使用承担角色而不是 AWS_PROFILE
- ruby-on-rails - 从大于 0 开始计数器缓存
- reactjs - React Native 拉动以从父级刷新部分列表
- c# - 基于给出不正确值的 Ticks 构造 DatetimeOffset 对象
- reactjs - Reactjs 在我输入时复制表单输入内容
- java - 有办法检测tomcat上的错误吗?
- c++ - 如何使用 openssl 解析具有奇怪 OID 的 x509 证书?
- python - 为什么在 Python 中使用 Robobrowser 进行网络抓取会导致“任务已被破坏,但它正在等待处理!”
- amazon-web-services - 处理传递给 AWS 数据管道中的 SQL 活动的参数