Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 数组超出检查功能的范围_Ios_Arrays_Swift_Uitableview - Fatal编程技术网

Ios 数组超出检查功能的范围

Ios 数组超出检查功能的范围,ios,arrays,swift,uitableview,Ios,Arrays,Swift,Uitableview,我有一个数组和一个检查函数 点击按钮时的功能: // 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

我有一个数组和一个检查函数

点击按钮时的功能:

// 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")
    }
}
我正在从以前的
viewcontroller
发送数字0到这个vc顶部的索引变量。我按下了check method
Finishexercise
,但无论我做什么,它都会一直计数。它说索引超出范围,但我正在检查索引是否等于或低于数组的计数

这是我想要实现的目标:

谁能帮帮我吗

非常感谢

我正在检查索引是否等于或低于数组的计数

对。但是,您是在增加索引之前执行此操作的,因为索引从零开始,所以应该在结束之前停止一个索引:

var index = 1 // Set the index to 1 initially to skip the title
...
if index+1 < workoutArray.count {
    index += 1
    tableView.reloadData()
    ...
}
var index=1//最初将索引设置为1以跳过标题
...
如果索引+1

上面的检查验证了
索引
在递增后是否会保持在范围内。

问题是我正在表格视图中显示结果。但是标题应该以1,2,3等开头。这是我在tableview中递增的原因。我为您添加了一张图片。因此,从上一个viewcontroller中,他得到了数字:0,但该数字将在生成单元格的tableview中被覆盖。index+1,因此它直接在加载上获取数字1避免返回空单元格
index
代表什么?这是当前训练的数量吗?索引表示:-当前训练中的套数。我会改变名字,因为它不是一个好名字
var index = 1 // Set the index to 1 initially to skip the title
...
if index+1 < workoutArray.count {
    index += 1
    tableView.reloadData()
    ...
}