' with an index of type ' Int'-6ren"> ' with an index of type ' Int'-我想为我的家庭作业准备一个基本的数字选择器计时器,但我无法解决这个问题。 var timer = Timer() var counter = 0 //let number = ["1"-6ren">
gpt4 book ai didi

ios - 如何快速修复 "Cannot subscript a value of type ' ClosedRange' with an index of type ' Int'

转载 作者:行者123 更新时间:2023-11-29 05:40:27 25 4
gpt4 key购买 nike

我想为我的家庭作业准备一个基本的数字选择器计时器,但我无法解决这个问题。

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/

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