Ios 在tableView中乘以值

Ios 在tableView中乘以值,ios,swift,uitableview,dictionary,Ios,Swift,Uitableview,Dictionary,我想根据字典中的行数动态生成单元格。在视图加载时,字典为空,并绑定在道路上。 字典与三个键值绑定良好,但当我想根据字典值和键值创建单元格时,总是使用字典中的最后一项创建三行 let dict = ["a": "first", "b": "second", "c": "third"] let arrayKeys = Array(dict.keys) let arrayValues = Array(dict.values) 我不明白为什么 这是我的代码: var perip

我想根据字典中的行数动态生成单元格。在视图加载时,字典为空,并绑定在道路上。
字典与三个键值绑定良好,但当我想根据字典值和键值创建单元格时,总是使用字典中的最后一项创建三行

    let dict = ["a": "first", "b": "second", "c": "third"]
    let arrayKeys = Array(dict.keys)
    let arrayValues = Array(dict.values)
我不明白为什么

这是我的代码:

var peripherals = [String:String]()

   override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print(peripherals.count)
    return peripherals.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)

    for (peripheralDeviceUUID,peripheralDeviceName) in peripherals {
         cell.textLabel?.text = "\(indexPath) \(peripheralDeviceName) : \(peripheralDeviceUUID)"
    }


    return cell
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return "Section \(section)"
}

首先从字典中创建键和值的数组

    let dict = ["a": "first", "b": "second", "c": "third"]
    let arrayKeys = Array(dict.keys)
    let arrayValues = Array(dict.values)
然后在cellForRow中使用这些数组:

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)    
          cell.textLabel?.text = "\(indexPath.row) \(arrayValues[indexPath.row]) : \(arrayKeys[indexPath.row])"
          return cell   
    }

首先从字典中创建键和值的数组

    let dict = ["a": "first", "b": "second", "c": "third"]
    let arrayKeys = Array(dict.keys)
    let arrayValues = Array(dict.values)
然后在cellForRow中使用这些数组:

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)    
          cell.textLabel?.text = "\(indexPath.row) \(arrayValues[indexPath.row]) : \(arrayKeys[indexPath.row])"
          return cell   
    }

只需删除循环并使用indexPath.row cell.textlab?.text=“(indexPath.row)(peripheralDeviceName):(peripheralDeviceUUID)”@Ralucalonescu字典中的键是什么?是否基于字典中的值来设置单元格数?正如您所说,字典中有3个键值,所以您希望基于数字或键显示单元格吗?或者基于值?只需删除循环并使用indexPath.row cell.textlab?.text=“(indexPath.row)(peripheralDeviceName):(peripheralDeviceUUID)”@Ralucalonescu字典中的键是什么?是否基于字典中的值设置单元格数?正如您所说,字典中有3个键值,所以您希望基于数字或键显示单元格吗?还是基于价值观?