【问题标题】:How can I display string values to multiple labels in a custom collectionView Cell in swift ios?如何在 swift ios 的自定义 collectionView 单元中将字符串值显示到多个标签?
【发布时间】:2016-12-17 13:40:58
【问题描述】:
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”字符串值来标记。我怎样才能做到这一点?我需要将它显示到我在自定义集合视图单元格中声明的标签

【问题讨论】:

    标签: ios uicollectionview swift3 uicollectionviewcell


    【解决方案1】:

    我想你可能想要一个 static UITableViewThis article may help(它很旧,但仍然相关)。基本上,如果在应用程序运行时不需要更改单元格的内容,则可以在情节提要中设置单元格的内容。但是,您当前的代码似乎还不错。如果这不是您要查找的问题,请提供有关该问题的更多信息。

    【讨论】:

    • 我已经声明了两个字符串,我想在自定义集合视图单元格中将一个字符串声明为一个标签,将第二个字符串声明为另一个标签。顺便说一句,我正在使用 xib。
    【解决方案2】:

    试试这个

    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
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多