gpt4 book ai didi

ios - TableView : Cannot subscript a value of type '[String]' with an index of type '[String]'

转载 作者:搜寻专家 更新时间:2023-10-31 22:25:09 25 4
gpt4 key购买 nike

我想将数组的项指定为索引以从另一个数组获取值。

var indexArray = ["0","5","10","15","20"]
var textArray = ["Tom","Teddy","Mark","John","Samuel","Smith","Chris","Paulo","Simon","Ralf","Mizo","Karim","Lady","Coloy","Samantha","Maro","Kathren","Lyla","Jessika","Amanda",]

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

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = textArray[indexArray[indexPath.row]]// here is an error Table View: Cannot subscript a value of type '[String]' with an index of type '[String]'

return cell
}

为了获得更多解释,不要使用 indexPath.row 作为 textArray 的索引,例如 (0, 1, 2, 3)。

我想使用 indexArray 中的索引(0、5、10、15、20)作为 textArray 的索引。

最佳答案

请更新以下行,

cell.textLabel?.text = textArray[Int(indexArray[indexPath.row])]

关于ios - TableView : Cannot subscript a value of type '[String]' with an index of type '[String]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50233257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com