![](/img/trans.png)
[英]How can I display multiple string values to multiple labels in a custom TableView Cell in swift ios?
[英]How can I display string values to multiple labels in a custom collectionView Cell in swift ios?
var leadername = ["1","2","3","4"]
var districts = ["Delhi","Kerala"]
override func viewDidLoad() {
leadTableSetup()
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func leadTableSetup(){
LeadTableView.delegate = self
LeadTableView.dataSource = self
self.LeadTableView.register(UINib(nibName: "LeaderBoardTableViewCell", bundle: nil), forCellReuseIdentifier: "leadCell")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 5
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 14
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "leadCell") as! LeaderBoardTableViewCell
// Set text from the data model
cell.areaLbl.text = districts[indexPath.row]
cell.leaderNameLbl.text = leadername[indexPath.row]
return cell
}
我需要在自定义视图单元格中显示“ leadername”和“ districts”字符串值以进行标记。如何实现? 我需要将其显示在自定义“收藏夹”视图单元格中声明的标签上
我认为您可能想拥有一个静态 UITableView
。 本文可能会有所帮助 (虽然年代久远,但仍然有意义)。 基本上,如果应用程序在运行时不需要更改,则可以在情节提要中设置单元格的内容。 但是,您当前的代码确实不错。 如果这不是您要的内容,请提供有关该问题的更多信息。
尝试这个
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "leadCell") as! LeaderBoardTableViewCell
// Set text from the data model
cell.leaderNameLbl.text = leadername[indexPath.row] + districts[indexPath.row % 2]
return cell
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.