【发布时间】:2016-10-10 15:21:40
【问题描述】:
我有一个数组和一个检查函数。
点击按钮时的功能:
// VARS
var workoutArray: [workout]!
var index = Int()
@IBAction func finishExerciseBtnPressed(_ sender: AnyObject) {
// reload tabledata with next exercise in array
print("the count of array is \(workoutArray.count)")
if index <= workoutArray.count {
index = index + 1
tableView.reloadData()
print("The exercise number is \(index)")
} else {
// Show finish workout button
print("No items found anymore")
}
}
tableViewdequeReusableCell的函数:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "workoutStartCell", for: indexPath) as? workoutStartCell {
let workout = workoutArray[index]
cell.updateUI(workout: workout, exercise: index + 1)
return cell
}else{
return UITableViewCell()
}
}
我正在从以前的viewcontroller 发送数字 0 到此 vc 顶部的索引 var。我有检查方法finishExercisePressed,但无论我在做什么,它都会一直计数低谷。它说索引超出范围,但我正在检查索引是否等于或低于数组的计数。
这是我想要达到的目标:
有人可以帮帮我吗?
非常感谢。
【问题讨论】:
-
避免返回空单元格
-
index代表什么?这是当前锻炼的编号吗? -
索引代表: - 当前锻炼的组数。我将更改名称,因为它不是一个好的命名
标签: ios arrays swift uitableview