【发布时间】:2017-05-04 10:03:05
【问题描述】:
我对 Swift 很陌生,问题是如何在标签中表示数组中的值。
我想要一个带有单元格的 TableView 动态地将数组中的值表示到将在 tableView 行中创建的标签中。
import UIKit
import Foundation
class TableViewMarketItemsViewCell: UITableViewController {
var fruits = ["Avocado", "Apricot", "Pomegranate", "Quince"]
var PriceArray = ["1000 тг.","4000 тг.","3000 тг.","2000 тг."]
var categoryArray = ["Green category","Maroon category","Red category","Yellow category"]
// MARK: - UITableViewDataSource
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fruits.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath) as! TableViewCell
let fruitName = fruits[indexPath.row]
cell.productTitle.text = fruitName
cell.productImage.image = UIImage(named: fruitName)
return cell
}
}
提前谢谢
【问题讨论】:
-
你已经尝试了什么?你经历了哪些教程,哪些没用,或者你不明白哪些?显示一些代码。
标签: ios arrays uitableview swift3 labels