【发布时间】:2017-07-26 12:04:32
【问题描述】:
我在表格视图中创建表格单元格,它们可以正确加载,您可以向下滚动它们,但如果您向上滚动应用程序会崩溃并显示错误 fatal error: Index out of range
这是生成表格单元格的代码
我对快速编码很陌生,所以请清楚你的答案
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return(tableRows.count)
}
var howmanyindex = 0
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ReviewControllerTableViewCell
cell.label1.text = profilerComments[tableRows[howmanyindex]]
cell.label2.text = String(profilerRatings[tableRows[howmanyindex]])
howmanyindex += 1
return(cell)
}
【问题讨论】:
-
不要手动处理索引。然后,您将不得不担心滚动的方向和所有内容,因此崩溃正在发生,因为当您向上滚动时,您的索引应该会减少,而这不会发生。直接使用 indexpath.row
标签: ios swift xcode uitableview