【问题标题】:looping tableview cell label text from an array从数组中循环tableview单元格标签文本
【发布时间】:2017-11-14 07:07:58
【问题描述】:

我有一个数组:

let BRIArray = ["ATM BRI", "Internet Banking BRI"]

然后我在 cellForRowAt 计算它:

let BRIArrayCount = BRIArray.count

然后我循环它:

for i in 0 ..< BRIArrayCount {
                print (i) //i will increment up one with each iteration of the for loop
                cell.lblBankPayment.text = "\(BRIArray[i])"
                print("BRIArray: \(BRIArray[i])")
            }

但结果只是得到最后一个字符串并如下图所示循环:

如何纠正 cellForRowAt 中的循环以在单元格标签文本中显示所有数组字符串?

【问题讨论】:

    标签: arrays uitableview swift3 tableview


    【解决方案1】:

    无需使用循环 而不是循环 只需使用

    cell.lblBankPayment.text = "(BRIArray[indexPath.row])"

    如果你想循环中的单个标签连接字符串中的所有文本然后设置它

    让 str = "(str)(" ")(BRIArray[index])"

    【讨论】:

    • 如果我这样设置 cell.lblBankPayment!.text = BRIArray[indexPath.row],有时会出现致命错误:索引超出范围
    • 你可以使用 if 语句检查 ex if BRIArray.count
    猜你喜欢
    • 2020-12-28
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多