在pickerView中的titleForRow中的for循环不起作用

我正在创建一个Clock PickerView,并使用了以下内容:

var countSec = Array(0...10)
var countMin = Array(0...59)
var countHour = Array(0...59)

func pickerView(_ pickerView: UIPickerView,titleForRow row: Int,forComponent component: Int) -> String? {
    if component == 0{
        for count in countSec {
            return "\(count)"
        }
    }else{
        for count in countMin{
            return "\(count)"
        }
    }
    return nil
}

但是当我运行时,所有数据都是0s。

csj871018 回答:在pickerView中的titleForRow中的for循环不起作用

请勿在{{1​​}}中使用循环。只需为请求的行返回适当的值即可。

==
本文链接:https://www.f2er.com/3164518.html

大家都在问