我想为我的家庭作业准备一个基本的数字选择器计时器,但我无法解决这个问题。
var timer = Timer()
var counter = 0
//let number = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"]
let number = 1 ... 60
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return number[row]
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return number.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
label.text = number[row]
}
但它给出了这个错误。
Cannot subscript a value of type 'ClosedRange' with an index of type 'Int'
最佳答案
您正在创建一个数组,因此需要用方括号括住该范围。
let numbers = [1...60]
关于ios - 如何快速修复 "Cannot subscript a value of type ' ClosedRange<Int >' with an index of type ' Int',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56609138/