从[String]()数组设置单元格textLabel

时间:2015-07-27 23:41:15

标签: arrays swift cell

尝试访问并将我的单元格textLabel和详细文本标签设置为已附加到数组的对象。我不确定如何在这种情况下使用正确的语法。谢谢你的帮助!

继承了我在for循环中解析后附加的对象。

var customers = [String]()


 for object in objects {

self.customers.append(object["customerName"] as! String)
self.customers.append(object["customerStreetAddress"] as! String)

  cellForRowAtIndexPath {


cell.textLabel.text = //I want the objects["customerName"] here
cell.detailTextLabel.text = // objects["customerStreetAddress"] here
}

1 个答案:

答案 0 :(得分:1)

你可以试试这个。

var customers = [String]()
var number = -1

for object in objects {

    self.customers.append(object["customerName"] as! String)
    self.customers.append(object["customerStreetAddress"] as! String)

    cellForRowAtIndexPath {

        ++number
        if number + 1 <= customers.count {
            cell.textLabel.text = customers[number]//I want the objects["customerName"] here
        }
        ++number
        if number + 1 <= customers.count {
            cell.detailTextLabel.text =  customers[number]// objects["customerStreetAddress"] here
        }
    }
}