表视图字典数组问题

时间:2017-09-17 11:24:08

标签: arrays dictionary tableview

我正在尝试让我的tableview正确地索引我的数组,但它会随机化表格视图中显示的字典值。我哪里错了?

代码如下:

  public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! _VCTableViewCell
    // Schemes

    let kbSchemes: [Int: [String]] = [
        0: ["1","2","3","4","5","6"],
        1: ["1","2","3","4","5","6"],
        2: ["1a","1b","2a","2b","3a","3b","4"],
        3: ["1a","1b","1c","1d","1e","1f"],
        4: ["1a","1b","1c","2a","2b","2c"]
    ]
    let randomSchemeIndex = Int(arc4random_uniform(UInt32(kbSchemes.count)))
    let schemeArray = kbSchemes[randomSchemeIndex]


    // Exercise, Sets & Reps
    let randomIndex = Int(arc4random_uniform(UInt32(kbDirectory.count)))
    let dictValues = Array(kbDirectory.values)
    let randomArray = dictValues[randomIndex]
    let randomArrayIndex = Int(arc4random_uniform(UInt32(randomArray.count)))
    let randomValue = randomArray[randomArrayIndex]
    let dictKeys = Array(kbDirectory.keys)

    // cell control
    cell.exerciseLabel?.text = dictKeys[randomIndex]
    cell.setRepLabel?.text = randomValue
    cell.numberLabel?.text = schemeArray?[indexPath.row]

    return cell

}

我还希望稍后在numberOfRowsInSection中为返回的kbSchemeArray提供.count属性,但是在将其置于正确的范围内时遇到问题。任何建议和/或建议表示赞赏。

0 个答案:

没有答案