gpt4 book ai didi

ios - Swift 超出范围....使用 tableView[indexPath]

转载 作者:行者123 更新时间:2023-11-28 09:35:41 25 4
gpt4 key购买 nike

我遇到了超出 range 错误的麻烦...

错误发生在cell.creditLabel.text = numOfDays[(indexPath as NSIndexPath).row] + "days"

如果我在 cell.nameLabel.text = nameArray[(indexPath as NSIndexPath).row] 之后放置 tableView.reloadData()

然后模拟器中什么也没有显示...

我该如何解决这个问题..?

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return self.nameArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell : MoneyTableViewCell = tableView.dequeueReusableCell(withIdentifier: "MoneyTableViewCell", for: indexPath) as! MoneyTableViewCell


cell.nameLabel.text = nameArray[(indexPath as NSIndexPath).row]

cell.creditLabel.text = numOfDays[(indexPath as NSIndexPath).row] + "days"
cell.levelLabel.text = creditArray[(indexPath as NSIndexPath).row]

cell.layoutIfNeeded()

return cell
}

最佳答案

您需要检查您的数组。从我在这里看到的情况来看,numOfDays 的元素少于 nameArray。此外,当你在那里时,也检查 creditArray :)

另外,不需要强制转换为 NSIndexPath

关于ios - Swift 超出范围....使用 tableView[indexPath],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45097448/

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